7 #include <QColorDialog>
10 #include <QDragEnterEvent>
11 #include <QDragLeaveEvent>
12 #include <QDragMoveEvent>
17 #include <QMouseEvent>
20 #include <QToolButton>
25 #include "ui_colorselector.h"
40 ui->tb_ColorDialog->setIcon(CIcons::color16());
48 completer->setMaxVisibleItems(10);
50 ui->le_Color->setCompleter(completer);
58 if (color == m_lastColor) {
return; }
66 ui->le_Color->setText(color.
hex());
67 ui->lbl_ColorIcon->setPixmap(color.
toPixmap());
83 ui->le_Color->setReadOnly(readOnly);
84 ui->tb_ColorDialog->setVisible(!readOnly);
90 ui->le_Color->clear();
91 ui->lbl_ColorIcon->setPixmap(
QPixmap());
96 if (!
event) {
return; }
98 event->acceptProposedAction();
103 if (!
event) {
return; }
104 event->acceptProposedAction();
111 if (!
event) {
return; }
112 const QMimeData *mime =
event->mimeData();
113 if (!mime) {
return; }
117 const auto color = qvariant_cast<QColor>(
event->mimeData()->colorData());
118 if (!color.isValid()) {
return; }
129 if (!rgb.isValid()) {
return; }
135 if (!qColor.isValid()) {
return; }
160 auto *drag =
new QDrag(
this);
164 drag->setMimeData(mimeData);
168 Q_UNUSED(dropAction);
171 void CColorSelector::colorDialog()
176 if (!newColor.
isValid()) {
return; }
180 void CColorSelector::onReturnPressed()
186 void CColorSelector::setColorByName(
const QString &colorName)
188 if (colorName.
isEmpty()) {
return; }
190 if (c.isValid()) { this->
setColor(c); }
193 void CColorSelector::resetToLastValidColor()
195 if (!m_lastColor.
isValid()) {
return; }
static swift::misc::CVariant fromSwiftDragAndDropData(const QMimeData *mime)
From text dropped.
static bool hasSwiftVariantMimeType(const QMimeData *mime)
Mime data with swift type.
void setReadOnly(bool readOnly)
Read only.
void colorChanged(const swift::misc::CRgbColor &color)
Color has been changed.
void mousePressEvent(QMouseEvent *event)
For dragging the color.
~CColorSelector()
Destructor.
void dropEvent(QDropEvent *event)
void dragEnterEvent(QDragEnterEvent *event)
void dragLeaveEvent(QDragLeaveEvent *event)
swift::misc::CRgbColor getColor() const
Selected color.
void dragMoveEvent(QDragMoveEvent *event)
void setColor(const swift::misc::CRgbColor &color)
Color.
QString hex(bool withHash=false) const
Hex value.
QPixmap toPixmap() const
Icon as pixmap.
QColor toQColor() const
To QColor.
bool isValid() const
Valid?
Wrapper around QVariant which provides transparent access to CValueObject methods of the contained ob...
T value() const
Return the value converted to the type T.
bool isValid() const
True if this variant is valid.
bool canConvert(int typeId) const
True if this variant can be converted to the type with the given metatype ID.
High level reusable GUI components.
Free functions in swift::misc.
bool isValid() const const
QColor getColor(const QColor &initial, QWidget *parent, const QString &title, QColorDialog::ColorDialogOptions options)
void activated(const QModelIndex &index)
virtual bool event(QEvent *e) override
bool hasColor() const const
bool hasText() const const
void setColorData(const QVariant &color)
QString text() const const
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
bool contains(QChar ch, Qt::CaseSensitivity cs) const const
bool isEmpty() const const
QVariant fromValue(T &&value)