Go to the documentation of this file.
26 #include <QMouseEvent>
28 #include <QApplication>
32 #include <QDragEnterEvent>
33 #include <QStyleOption>
88 else if ( columns == 0 )
91 int rows = std::ceil(
float(count) / columns );
93 return QSize(columns, rows);
107 if (
event->mimeData()->hasColor() )
109 drop_color =
event->mimeData()->colorData().value<QColor>();
112 else if (
event->mimeData()->hasText() )
125 if (
event->posF().y() >= drop_rect.top() + drop_rect.height() * 3.0 / 4 )
128 else if (
event->posF().x() > drop_rect.top() + drop_rect.height() / 4 &&
129 (
event->dropAction() != Qt::MoveAction ||
event->source() !=
owner ) )
135 if (
event->posF().x() >= drop_rect.left() + drop_rect.width() * 3.0 / 4 )
138 else if (
event->posF().x() > drop_rect.left() + drop_rect.width() / 4 &&
139 (
event->dropAction() != Qt::MoveAction ||
event->source() !=
owner ) )
165 if ( !rowcols.isValid() )
204 if ( index == -1 || !rc.isValid() )
211 : QWidget(parent), p(new
Private(this))
217 if ( index == p->selected )
218 emit colorSelected( p->palette.colorAt(index) );
221 if ( index == p->selected )
224 setFocusPolicy(Qt::StrongFocus);
225 setAcceptDrops(
true);
226 setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
227 setAttribute(Qt::WA_Hover,
true);
239 if ( !
p->
color_size.isValid() || !rowcols.isValid() )
278 if ( rowcols.isEmpty() )
284 qBound<int>(0, pt.x() / color_size.width(), rowcols.width() - 1),
285 qBound<int>(0, pt.y() / color_size.height(), rowcols.height() - 1)
288 int index = point.y() * rowcols.width() + point.x();
329 if ( rowcols.isEmpty() )
333 QPainter painter(
this);
335 QStyleOptionFrame panel;
336 panel.initFrom(
this);
338 panel.midLineWidth = 0;
339 panel.state |= QStyle::State_Sunken;
340 style()->drawPrimitive(QStyle::PE_Frame, &panel, &painter,
this);
341 QRect r = style()->subElementRect(QStyle::SE_FrameContents, &panel,
this);
342 painter.setClipRect(r);
346 for (
int y = 0, i = 0; i < count;
y++ )
348 for (
int x = 0;
x < rowcols.width() && i < count;
x++, i++ )
351 painter.drawRect(
p->
indexRect(i, rowcols, color_size));
355 painter.setClipping(
false);
363 painter.setPen(QPen(Qt::gray));
364 painter.drawRect(drop_area);
366 else if ( rowcols.width() == 1 )
370 painter.setBrush(Qt::transparent);
371 painter.drawLine(drop_area.topLeft(), drop_area.topRight());
376 painter.setBrush(Qt::transparent);
377 painter.drawLine(drop_area.topLeft(), drop_area.bottomLeft());
382 drop_area.translate(color_size.width(), 0);
383 painter.drawLine(drop_area.topLeft(), drop_area.bottomLeft());
391 painter.setBrush(Qt::transparent);
392 painter.setPen(QPen(Qt::darkGray, 2));
393 painter.drawRect(rect);
394 painter.setPen(QPen(Qt::gray, 2, Qt::DotLine));
395 painter.drawRect(rect);
402 QWidget::keyPressEvent(
event);
407 int columns = rowcols.width();
408 int rows = rowcols.height();
409 switch (
event->key() )
412 QWidget::keyPressEvent(
event);
439 else if (
selected < count - columns )
444 if (
event->modifiers() & Qt::ControlModifier )
451 if (
event->modifiers() & Qt::ControlModifier )
461 case Qt::Key_Backspace:
478 case Qt::Key_PageDown:
506 if (
event->button() == Qt::LeftButton )
512 else if (
event->button() == Qt::RightButton )
523 (
p->
drag_pos -
event->pos()).manhattanLength() >= QApplication::startDragDistance() )
527 QPixmap preview(24,24);
530 QMimeData *mimedata =
new QMimeData;
531 mimedata->setColorData(
color);
534 QDrag *drag =
new QDrag(
this);
535 drag->setMimeData(mimedata);
536 drag->setPixmap(preview);
537 Qt::DropActions actions = Qt::CopyAction;
539 actions |= Qt::MoveAction;
546 if (
event->button() == Qt::LeftButton )
554 if (
event->button() == Qt::LeftButton )
564 if (
event->delta() > 0 )
582 if (
event->proposedAction() == Qt::MoveAction &&
event->source() ==
this )
583 event->setDropAction(Qt::MoveAction);
585 event->setDropAction(Qt::CopyAction);
611 if (
event->mimeData()->hasColor() &&
event->mimeData()->hasText() )
612 name =
event->mimeData()->text();
621 if (
event->dropAction() == Qt::MoveAction &&
event->source() ==
this )
686 setFixedSize(QWIDGETSIZE_MAX,QWIDGETSIZE_MAX);
744 QHelpEvent* help_ev =
static_cast<QHelpEvent*
>(
event);
745 int index =
indexAt(help_ev->pos());
750 QString message =
color.name();
751 if ( !name.isEmpty() )
752 message = tr(
"%1 (%2)").arg(name).arg(message);
753 message =
"<tt style='background-color:"+
color.name()+
";color:"+
color.name()+
";'>MM</tt> "+message.toHtmlEscaped();
754 QToolTip::showText(help_ev->globalPos(), message,
this,
760 QToolTip::hideText();
766 return QWidget::event(
event);
void update(const std::string &key, const XmlRpc::XmlRpcValue &v)
plotjuggler
Author(s): Davide Faconti
autogenerated on Mon Nov 11 2024 03:23:47