void CustomPalette::loadColors( QPtrList<Color> colors ) { clear(); QPtrList<Color> empty; k_toon -> document() -> getPalette() -> setColors( empty ); Color *c_it; for ( c_it = colors.first(); c_it; c_it = colors.next() ) { sel_row = cur_row; sel_col = cur_col; QColor nc = QColor( ( int )( c_it -> colorRed() * 255.0 ), ( int )( c_it -> colorGreen() * 255.0 ), ( int )( c_it -> colorBlue() * 255.0 ) ); int a = ( int )( c_it -> colorAlpha() * 100.0 ); slotAddColor( nc, a ); slotChangeColorName( c_it -> nameColor() ); } }
// --- StyleSheetEditorDialog StyleSheetEditorDialog::StyleSheetEditorDialog(QDesignerFormEditorInterface *core, QWidget *parent, Mode mode): QDialog(parent), m_buttonBox(new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel|QDialogButtonBox::Help)), m_editor(new StyleSheetEditor), m_validityLabel(new QLabel(tr("Valid Style Sheet"))), m_core(core), m_addResourceAction(new QAction(tr("Add Resource..."), this)), m_addGradientAction(new QAction(tr("Add Gradient..."), this)), m_addColorAction(new QAction(tr("Add Color..."), this)), m_addFontAction(new QAction(tr("Add Font..."), this)) { setWindowTitle(tr("Edit Style Sheet")); setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); connect(m_buttonBox, SIGNAL(accepted()), this, SLOT(accept())); connect(m_buttonBox, SIGNAL(rejected()), this, SLOT(reject())); connect(m_buttonBox, SIGNAL(helpRequested()), this, SLOT(slotRequestHelp())); m_buttonBox->button(QDialogButtonBox::Help)->setShortcut(QKeySequence::HelpContents); connect(m_editor, SIGNAL(textChanged()), this, SLOT(validateStyleSheet())); QToolBar *toolBar = new QToolBar; QGridLayout *layout = new QGridLayout; layout->addWidget(toolBar, 0, 0, 1, 2); layout->addWidget(m_editor, 1, 0, 1, 2); layout->addWidget(m_validityLabel, 2, 0, 1, 1); layout->addWidget(m_buttonBox, 2, 1, 1, 1); setLayout(layout); m_editor->setContextMenuPolicy(Qt::CustomContextMenu); connect(m_editor, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(slotContextMenuRequested(QPoint))); QSignalMapper *resourceActionMapper = new QSignalMapper(this); QSignalMapper *gradientActionMapper = new QSignalMapper(this); QSignalMapper *colorActionMapper = new QSignalMapper(this); resourceActionMapper->setMapping(m_addResourceAction, QString()); gradientActionMapper->setMapping(m_addGradientAction, QString()); colorActionMapper->setMapping(m_addColorAction, QString()); connect(m_addResourceAction, SIGNAL(triggered()), resourceActionMapper, SLOT(map())); connect(m_addGradientAction, SIGNAL(triggered()), gradientActionMapper, SLOT(map())); connect(m_addColorAction, SIGNAL(triggered()), colorActionMapper, SLOT(map())); connect(m_addFontAction, SIGNAL(triggered()), this, SLOT(slotAddFont())); m_addResourceAction->setEnabled(mode == ModePerForm); const char * const resourceProperties[] = { "background-image", "border-image", "image", 0 }; const char * const colorProperties[] = { "color", "background-color", "alternate-background-color", "border-color", "border-top-color", "border-right-color", "border-bottom-color", "border-left-color", "gridline-color", "selection-color", "selection-background-color", 0 }; QMenu *resourceActionMenu = new QMenu(this); QMenu *gradientActionMenu = new QMenu(this); QMenu *colorActionMenu = new QMenu(this); for (int resourceProperty = 0; resourceProperties[resourceProperty]; ++resourceProperty) { QAction *action = resourceActionMenu->addAction(QLatin1String(resourceProperties[resourceProperty])); connect(action, SIGNAL(triggered()), resourceActionMapper, SLOT(map())); resourceActionMapper->setMapping(action, QLatin1String(resourceProperties[resourceProperty])); } for (int colorProperty = 0; colorProperties[colorProperty]; ++colorProperty) { QAction *gradientAction = gradientActionMenu->addAction(QLatin1String(colorProperties[colorProperty])); QAction *colorAction = colorActionMenu->addAction(QLatin1String(colorProperties[colorProperty])); connect(gradientAction, SIGNAL(triggered()), gradientActionMapper, SLOT(map())); connect(colorAction, SIGNAL(triggered()), colorActionMapper, SLOT(map())); gradientActionMapper->setMapping(gradientAction, QLatin1String(colorProperties[colorProperty])); colorActionMapper->setMapping(colorAction, QLatin1String(colorProperties[colorProperty])); } connect(resourceActionMapper, SIGNAL(mapped(QString)), this, SLOT(slotAddResource(QString))); connect(gradientActionMapper, SIGNAL(mapped(QString)), this, SLOT(slotAddGradient(QString))); connect(colorActionMapper, SIGNAL(mapped(QString)), this, SLOT(slotAddColor(QString))); m_addResourceAction->setMenu(resourceActionMenu); m_addGradientAction->setMenu(gradientActionMenu); m_addColorAction->setMenu(colorActionMenu); toolBar->addAction(m_addResourceAction); toolBar->addAction(m_addGradientAction); toolBar->addAction(m_addColorAction); toolBar->addAction(m_addFontAction); m_editor->setFocus(); QDesignerSettingsInterface *settings = core->settingsManager(); settings->beginGroup(QLatin1String(StyleSheetDialogC)); if (settings->contains(QLatin1String(Geometry))) restoreGeometry(settings->value(QLatin1String(Geometry)).toByteArray()); settings->endGroup(); }