QScriptValue ColorDialog::constructor(QScriptContext *context, QScriptEngine *engine) { ColorDialog *colorDialog = new ColorDialog; colorDialog->setupConstructorParameters(context, engine, context->argument(0)); QScriptValueIterator it(context->argument(0)); while(it.hasNext()) { it.next(); if(it.name() == "showAlphaChannel") colorDialog->mColorDialog->setOption(QColorDialog::ShowAlphaChannel, it.value().toBool()); else if(it.name() == "color") colorDialog->setColorPrivate(it.value(), context); else if(it.name() == "onClosed") colorDialog->mOnClosed = it.value(); else if(it.name() == "onColorSelected") colorDialog->mOnColorSelected = it.value(); else if(it.name() == "onColorChanged") colorDialog->mOnColorChanged = it.value(); } return CodeClass::constructor(colorDialog, context, engine); }
bool ColorDelegate::editorEvent(QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option, const QModelIndex& index) { if ( event->type() == QEvent::MouseButtonRelease && index.data().canConvert<QColor>()) { QMouseEvent* mouse_event = static_cast<QMouseEvent*>(event); if ( mouse_event->button() == Qt::LeftButton && ( index.flags() & Qt::ItemIsEditable) ) { ColorDialog *editor = new ColorDialog(const_cast<QWidget*>(option.widget)); connect(this, &QObject::destroyed, editor, &QObject::deleteLater); editor->setMinimumSize(editor->sizeHint()); auto original_color = index.data().value<QColor>(); editor->setColor(original_color); auto set_color = [model, index](const QColor& color){ model->setData(index, QVariant(color)); }; connect(editor, &ColorDialog::colorSelected, this, set_color); editor->show(); } return true; } return QAbstractItemDelegate::editorEvent(event, model, option, index); }
/** Shows a color dialog and hides this dialog temporarily. * Also, reorder the mainWindow and the color dialog to avoid overlapping, if possible. */ void CustomizeThemeDialog::showColorDialog() { _targetedColor = findChild<Reflector*>(sender()->objectName().replace("ToolButton", "Widget")); if (_targetedColor) { QPalette::ColorRole cr = _targetedColor->colorRole(); _targetedColor->setColor(QApplication::palette().color(cr)); this->setAttribute(Qt::WA_DeleteOnClose, false); ColorDialog *colorDialog = new ColorDialog(this); colorDialog->setCurrentColor(_targetedColor->color()); this->hide(); int i = colorDialog->exec(); if (i >= 0) { // Automatically adjusts Reflector Widgets for Text colors if one hasn't check the option if (!SettingsPrivate::instance()->isCustomTextColorOverriden()) { QPalette palette = QApplication::palette(); if (cr == QPalette::Base) { fontColorWidget->setColor(palette.color(QPalette::Text)); } else if (cr == QPalette::Highlight) { selectedFontColorWidget->setColor(palette.color(QPalette::HighlightedText)); } } this->show(); this->setAttribute(Qt::WA_DeleteOnClose); } } }
void ColorDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const { if (index.data().canConvert<QColor>()) { ColorDialog *selector = qobject_cast<ColorDialog *>(editor); model->setData(index, QVariant::fromValue(selector->color())); } else QStyledItemDelegate::setModelData(editor, model, index); }
void ColorDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const { if (index.data().canConvert<QColor>()) { ColorDialog *selector = qobject_cast<ColorDialog*>(editor); selector->setColor(qvariant_cast<QColor>(index.data())); } else QStyledItemDelegate::setEditorData(editor, index); }
/** Shows a color dialog and hides this dialog temporarily. * Also, reorder the mainWindow and the color dialog to avoid overlapping, if possible. */ void CustomizeThemeDialog::showColorDialog() { _targetedColor = findChild<Reflector*>(sender()->objectName().replace("ToolButton", "Widget")); if (_targetedColor) { qDebug() << _targetedColor->objectName() << _targetedColor->color(); _targetedColor->setColor(SettingsPrivate::instance()->customColors(_targetedColor->colorRole())); qDebug() << _targetedColor->objectName() << _targetedColor->color(); ColorDialog *colorDialog = new ColorDialog(this); colorDialog->setCurrentColor(_targetedColor->color()); //qDebug() << colorDialog->currentColor() << _targetedColor->color(); this->hide(); colorDialog->exec(); } }
QWidget *ColorDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const { if (index.data().canConvert<QColor>()) { ColorDialog *editor = new ColorDialog(parent); editor->setMinimumSize(editor->sizeHint()); connect(editor, SIGNAL(colorChanged(QColor)), this, SLOT(color_changed())); connect(editor, SIGNAL(accepted()), this, SLOT(close_editor())); return editor; } else return QStyledItemDelegate::createEditor(parent, option, index); }
void Editor::editColor() { if (!activeStack() || selection_->empty()) return; KMenu menu(i18n("Select Color")); menu.addTitle(i18n("Shortcuts")); ColorManager *cm = Application::self()->colorManager(); foreach (const ldraw::color &it, cm->colorList()) { QAction *action = menu.addAction(QIcon(ColorManager::colorPixmap(it)), it.get_entity()->name.c_str()); action->setData(it.get_id()); } menu.addTitle(i18n("Recently Used")); foreach (const ColorManager::RecentColorPair &it, cm->recentlyUsed()) { QAction *action = menu.addAction(QIcon(ColorManager::colorPixmap(it.first)), it.first.get_entity()->name.c_str()); action->setData(it.first.get_id()); } menu.addSeparator(); QAction *customize = menu.addAction(i18n("&More...")); QAction *result = menu.exec(QCursor::pos()); if (result) { if (result == customize) { ColorDialog *colordialog = new ColorDialog(Application::self()->rootWindow()); if (colordialog->exec() == QDialog::Accepted) { activeStack()->push(new CommandColor(colordialog->getSelected(), *selection_, model_)); cm->hit(colordialog->getSelected()); emit modified(); } delete colordialog; } else { ldraw::color selected(result->data().toInt()); activeStack()->push(new CommandColor(selected, *selection_, model_)); cm->hit(selected); emit modified(); } } }
int main(int argc, char *argv[]) { QApplication a(argc, argv); ColorListWidget c; c.show(); ColorDialog w; w.setColor(QColor(64,172,143,128)); w.show(); /*QPixmap p(w.size()); w.render(&p); p.save("screenshot.png");*/ return a.exec(); }