19 #include <QChildEvent> 23 #include <QMouseEvent> 26 #include <qwt/qwt_dyngrid_layout.h> 27 #if QWT_VERSION >= 0x060100 28 #include <qwt/qwt_legend_label.h> 29 #include <qwt/qwt_plot_legenditem.h> 31 #include <qwt/qwt_legend_item.h> 32 #include <qwt/qwt_legend_itemmanager.h> 50 QwtDynGridLayout* layout =
static_cast<QwtDynGridLayout*
>(
51 contentsWidget()->layout());
52 layout->setSpacing(10);
63 #if QWT_VERSION >= 0x060100 64 QVariant info = itemInfo(widget);
66 if (info.canConvert<QwtPlotItem*>())
67 return dynamic_cast<PlotCurve*
>(info.value<QwtPlotItem*>());
71 QwtLegendItemManager* legendItemManager = find(widget);
73 if (legendItemManager)
74 return dynamic_cast<PlotCurve*
>(legendItemManager);
81 if (
object == contentsWidget()) {
82 if (event->type() == QEvent::ChildAdded) {
83 QChildEvent* childEvent =
static_cast<QChildEvent*
>(event);
85 #if QWT_VERSION >= 0x060100 86 QwtLegendLabel* legendItem = qobject_cast<QwtLegendLabel*>(
89 QwtLegendItem* legendItem = qobject_cast<QwtLegendItem*>(
94 legendItem->setCursor(Qt::PointingHandCursor);
95 legendItem->installEventFilter(
this);
99 else if (object->isWidgetType()) {
100 QWidget* widget =
static_cast<QWidget*
>(object);
104 if (event->type() == QEvent::MouseButtonDblClick) {
108 dialog.setWindowTitle(curveConfig->
getTitle().isEmpty() ?
110 "Edit \""+curveConfig->
getTitle()+
"\"");
113 if (dialog.exec() == QDialog::Accepted)
116 else if (event->type() == QEvent::MouseButtonPress) {
117 QMouseEvent* mouseEvent =
static_cast<QMouseEvent*
>(event);
119 if ((mouseEvent->button() == Qt::LeftButton) ||
120 (mouseEvent->button() == Qt::RightButton)) {
122 QDataStream stream(&data, QIODevice::WriteOnly);
125 QMimeData* mimeData =
new QMimeData();
128 QPixmap pixmap(widget->size());
129 pixmap.fill(Qt::transparent);
130 widget->render(&pixmap, QPoint(), QRegion(), QWidget::DrawChildren);
132 QPoint hotSpot = mouseEvent->pos();
133 hotSpot.setX(0.5*pixmap.width());
134 hotSpot.setY(pixmap.height()+5);
136 QDrag* drag =
new QDrag(
this);
137 drag->setMimeData(mimeData);
138 drag->setPixmap(pixmap);
139 drag->setHotSpot(hotSpot);
141 Qt::DropAction defaultDropAction = Qt::CopyAction;
142 if (mouseEvent->button() == Qt::RightButton)
143 defaultDropAction = Qt::MoveAction;
145 Qt::DropAction dropAction = drag->exec(Qt::CopyAction |
146 Qt::MoveAction, defaultDropAction);
148 if (dropAction == Qt::MoveAction)
155 return QwtLegend::eventFilter(
object, event);
static const QString MimeType
bool eventFilter(QObject *object, QEvent *event)
CurveConfig * getConfig() const
PlotLegend(QWidget *parent)
PlotCurve * findCurve(QWidget *widget) const
CurveConfigWidget * getWidget() const
const QString & getTitle() const