git-svn-id: svn://db.shs.com.ru/libs@380 a8b55f48-bf90-11e4-a774-851b48703e85
This commit is contained in:
@@ -1,11 +1,60 @@
|
||||
#include "cdgraphics.h"
|
||||
#include "cdutils_core.h"
|
||||
#include "cdutils_x.h"
|
||||
#include "qcd_core.h"
|
||||
#include "qcd_model.h"
|
||||
#include "graphic.h"
|
||||
#include "piqt.h"
|
||||
#include <QMimeData>
|
||||
#include <QDragEnterEvent>
|
||||
#include <QDragMoveEvent>
|
||||
#include <QDropEvent>
|
||||
#include <QMainWindow>
|
||||
#include <QDockWidget>
|
||||
#include <QInputDialog>
|
||||
|
||||
using namespace CDUtils;
|
||||
|
||||
|
||||
GDockWidget::GDockWidget(QString title, QMainWindow * p): QDockWidget(title, p) {
|
||||
da = p;
|
||||
menu = new QMenu(this);
|
||||
QAction * a = new QAction(QIcon(":/icons/document-edit.png"), "Rename ...", this);
|
||||
connect(a, SIGNAL(triggered(bool)), this, SLOT(rename()));
|
||||
dactions << a;
|
||||
a = new QAction(QIcon(":/icons/edit-delete.png"), "Remove", this);
|
||||
connect(a, SIGNAL(triggered(bool)), this, SIGNAL(removeRequest()));
|
||||
dactions << a;
|
||||
}
|
||||
|
||||
|
||||
void GDockWidget::contextMenuEvent(QContextMenuEvent * e) {
|
||||
QMenu * mwm = da->createPopupMenu();
|
||||
menu->clear();
|
||||
menu->addActions(dactions);
|
||||
menu->addSeparator();
|
||||
menu->addActions(mwm->actions());
|
||||
menu->popup(e->globalPos());
|
||||
mwm->deleteLater();
|
||||
}
|
||||
|
||||
|
||||
void GDockWidget::rename() {
|
||||
QString nn = QInputDialog::getText(this, trUtf8("Rename area"), trUtf8("New area name:"),
|
||||
QLineEdit::Normal, windowTitle());
|
||||
if (nn.isEmpty()) return;
|
||||
setWindowTitle(nn);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
CDGraphics::CDGraphics(QWidget * parent) : QWidget(parent), Ui::CDGraphics() {
|
||||
setupUi(this);
|
||||
da = new QMainWindow();
|
||||
da->setWindowFlags(frame->windowFlags());
|
||||
da->setDockNestingEnabled(true);
|
||||
layoutMain->addWidget(da);
|
||||
}
|
||||
|
||||
|
||||
@@ -15,3 +64,97 @@ CDGraphics::~CDGraphics() {
|
||||
|
||||
void CDGraphics::reset() {
|
||||
}
|
||||
|
||||
|
||||
bool CDGraphics::eventFilter(QObject * o, QEvent * e) {
|
||||
//if (o == graphic->viewport()) {
|
||||
switch (e->type()) {
|
||||
case QEvent::DragEnter: {
|
||||
QDragEnterEvent * de = (QDragEnterEvent*)e;
|
||||
const QMimeData * mime = de->mimeData();
|
||||
//qDebug() << "enter" << mime;
|
||||
if (!mime) break;
|
||||
if (mime->text().isEmpty()) break;
|
||||
de->setDropAction(Qt::CopyAction);
|
||||
de->accept();
|
||||
return true;
|
||||
} break;
|
||||
case QEvent::Drop: {
|
||||
QDropEvent * de = (QDropEvent*)e;
|
||||
const QMimeData * mime = de->mimeData();
|
||||
if (!mime) break;
|
||||
//qDebug() << "drop" << mime->text();
|
||||
if (mime->text().isEmpty()) break;
|
||||
addXToGraphic(mime->text(), viewportGraphic(o));
|
||||
de->accept();
|
||||
return true;
|
||||
} break;
|
||||
default: break;
|
||||
}
|
||||
//}
|
||||
return QWidget::eventFilter(o, e);
|
||||
}
|
||||
|
||||
|
||||
Graphic * CDGraphics::viewportGraphic(QObject * o) const {
|
||||
if (!o) return 0;
|
||||
while (!qobject_cast<Graphic*>(o) && o)
|
||||
o = o->parent();
|
||||
return qobject_cast<Graphic*>(o);
|
||||
}
|
||||
|
||||
|
||||
void CDGraphics::addGraphic() {
|
||||
Graphic * g = new Graphic();
|
||||
g->setGraphicsCount(0);
|
||||
g->setBorderInputsVisible(false);
|
||||
g->setLegendVisible(true);
|
||||
g->viewport()->setAcceptDrops(true);
|
||||
g->viewport()->installEventFilter(this);
|
||||
GDockWidget * dw = new GDockWidget(QString("graphics %1").arg(graphics.size()), da);
|
||||
connect(dw, SIGNAL(removeRequest()), this, SLOT(removeGraphic()));
|
||||
dw->setWidget(g);
|
||||
da->addDockWidget(Qt::RightDockWidgetArea, dw);
|
||||
docks << dw;
|
||||
graphics << g;
|
||||
}
|
||||
|
||||
|
||||
void CDGraphics::removeGraphic() {
|
||||
GDockWidget * d = qobject_cast<GDockWidget * >(sender());
|
||||
if (!d) return;
|
||||
Graphic * g = qobject_cast<Graphic * >(d->widget());
|
||||
docks.removeAll(d);
|
||||
graphics.removeAll(g);
|
||||
g->deleteLater();
|
||||
d->deleteLater();
|
||||
}
|
||||
|
||||
|
||||
void CDGraphics::addXToGraphic(const QString & xp, Graphic * g) {
|
||||
qDebug() << "addGraphic" << xp << g;
|
||||
if (xp.isEmpty() || !g) return;
|
||||
CDType & t(X[CDCore::stringToPath(Q2PIString(xp))]);
|
||||
int gind = g->graphicsCount();
|
||||
g->setGraphicsCount(gind + 1);
|
||||
g->setGraphicName(PI2QString(t.pathString().join(".")), gind);
|
||||
}
|
||||
|
||||
|
||||
void CDGraphics::on_buttonAdd_clicked() {
|
||||
addGraphic();
|
||||
}
|
||||
|
||||
|
||||
void CDGraphics::on_buttonClear_clicked() {
|
||||
foreach (Graphic * g, graphics)
|
||||
g->clear();
|
||||
}
|
||||
|
||||
|
||||
void CDGraphics::on_buttonRemoveAll_clicked() {
|
||||
qDeleteAll(graphics);
|
||||
qDeleteAll(docks);
|
||||
graphics.clear();
|
||||
docks.clear();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user