KColorDialog::KColorDialog(QWidget *parent) : QWidget(parent), d(new KColorDialogPrivate(this)) { // setCaption(tr("Select Color")); // setButtons(modal ? Ok | Cancel : Close); // showButtonSeparator(true); // setModal(modal); d->bRecursion = true; d->bColorPicking = false; #ifdef Q_WS_X11 d->filter = 0; #endif d->cbDefaultColor = 0L; d->_mode = ChooserClassic; QLabel *label; QGridLayout *tl_layout = new QGridLayout(this); tl_layout->setMargin(0); tl_layout->setSpacing(1); d->tl_layout = tl_layout; tl_layout->addItem(new QSpacerItem(1*2, 0), 0, 1); // // the more complicated part: the left side // add a V-box // QVBoxLayout *l_left = new QVBoxLayout(); tl_layout->addLayout(l_left, 0, 0); // // add a H-Box for the XY-Selector and a grid for the // entry fields // QHBoxLayout *l_ltop = new QHBoxLayout(); l_left->addLayout(l_ltop); // a little space between l_left->addSpacing(10); QGridLayout *l_lbot = new QGridLayout(); l_left->addLayout(l_lbot); // // the palette and value selector go into the H-box // d->hsSelector = new KHueSaturationSelector(this); d->hsSelector->setMinimumSize(256, 256); l_ltop->addWidget(d->hsSelector, 8); connect(d->hsSelector, SIGNAL(valueChanged(int, int)), SLOT(slotHSChanged(int, int))); d->valuePal = new KColorValueSelector(this); d->valuePal->setMinimumSize(26, 70); d->valuePal->setIndent(false); d->valuePal->setArrowDirection(Qt::RightArrow); l_ltop->addWidget(d->valuePal, 1); connect(d->valuePal, SIGNAL(valueChanged(int)), SLOT(slotVChanged(int))); // // add the HSV fields // l_lbot->setColumnStretch(2, 10); d->hmode = new QRadioButton(tr("Hue:"), this); l_lbot->addWidget(d->hmode, 0, 0); d->hedit = new KColorSpinBox(0, 359, 1, this); l_lbot->addWidget(d->hedit, 0, 1); connect(d->hedit, SIGNAL(valueChanged(int)), SLOT(slotHSVChanged())); connect(d->hmode, SIGNAL(clicked()), SLOT(setHMode())); d->smode = new QRadioButton(tr("Saturation:"), this); l_lbot->addWidget(d->smode, 1, 0); d->sedit = new KColorSpinBox(0, 255, 1, this); l_lbot->addWidget(d->sedit, 1, 1); connect(d->sedit, SIGNAL(valueChanged(int)), SLOT(slotHSVChanged())); connect(d->smode, SIGNAL(clicked()), SLOT(setSMode())); d->vmode = new QRadioButton(tr("Value:"), this); l_lbot->addWidget(d->vmode, 2, 0); d->vedit = new KColorSpinBox(0, 255, 1, this); l_lbot->addWidget(d->vedit, 2, 1); connect(d->vedit, SIGNAL(valueChanged(int)), SLOT(slotHSVChanged())); connect(d->vmode, SIGNAL(clicked()), SLOT(setVMode())); // // add the RGB fields // d->rmode = new QRadioButton(tr("Red:"), this); l_lbot->addWidget(d->rmode, 0, 3); d->redit = new KColorSpinBox(0, 255, 1, this); l_lbot->addWidget(d->redit, 0, 4); connect(d->redit, SIGNAL(valueChanged(int)), SLOT(slotRGBChanged())); connect(d->rmode, SIGNAL(clicked()), SLOT(setRMode())); d->gmode = new QRadioButton(tr("Green:"), this); l_lbot->addWidget(d->gmode, 1, 3); d->gedit = new KColorSpinBox(0, 255, 1, this); l_lbot->addWidget(d->gedit, 1, 4); connect(d->gedit, SIGNAL(valueChanged(int)), SLOT(slotRGBChanged())); connect(d->gmode, SIGNAL(clicked()), SLOT(setGMode())); d->bmode = new QRadioButton(tr("Blue:"), this); l_lbot->addWidget(d->bmode, 2, 3); d->bedit = new KColorSpinBox(0, 255, 1, this); l_lbot->addWidget(d->bedit, 2, 4); connect(d->bedit, SIGNAL(valueChanged(int)), SLOT(slotRGBChanged())); connect(d->bmode, SIGNAL(clicked()), SLOT(setBMode())); // // the entry fields should be wide enough to hold 8888888 // int w = d->hedit->fontMetrics().width("8888888"); d->hedit->setFixedWidth(w); d->sedit->setFixedWidth(w); d->vedit->setFixedWidth(w); d->redit->setFixedWidth(w); d->gedit->setFixedWidth(w); d->bedit->setFixedWidth(w); // // add a layout for the right side // d->l_right = new QVBoxLayout; tl_layout->addLayout(d->l_right, 0, 2); // // Add the palette table // d->table = new KColorTable(this); d->l_right->addWidget(d->table, 10); connect(d->table, SIGNAL(colorSelected(const QColor &, const QString &)), SLOT(slotColorSelected(const QColor &, const QString &))); connect( d->table, SIGNAL(colorDoubleClicked(const QColor &, const QString &)), SLOT(slotColorDoubleClicked(const QColor &, const QString &)) ); // Store the default value for saving time. d->originalPalette = d->table->name(); // // a little space between // d->l_right->addSpacing(10); QHBoxLayout *l_hbox = new QHBoxLayout(); d->l_right->addItem(l_hbox); // // The add to custom colors button // QPushButton *addButton = new QPushButton(this); addButton->setText(tr("&Add to Custom Colors")); l_hbox->addWidget(addButton, 0, Qt::AlignLeft); connect(addButton, SIGNAL(clicked()), SLOT(slotAddToCustomColors())); // // The color picker button // QPushButton* button = new QPushButton(this); button->setIcon(QIcon("color-picker")); int commonHeight = addButton->sizeHint().height(); button->setFixedSize(commonHeight, commonHeight); l_hbox->addWidget(button, 0, Qt::AlignHCenter); connect(button, SIGNAL(clicked()), SLOT(slotColorPicker())); // // a little space between // d->l_right->addSpacing(10); // // and now the entry fields and the patch (=colored box) // QGridLayout *l_grid = new QGridLayout(); d->l_right->addLayout(l_grid); l_grid->setColumnStretch(2, 1); label = new QLabel(this); label->setText(tr("Name:")); l_grid->addWidget(label, 0, 1, Qt::AlignLeft); d->colorName = new QLabel(this); l_grid->addWidget(d->colorName, 0, 2, Qt::AlignLeft); label = new QLabel(this); label->setText(tr("HTML:")); l_grid->addWidget(label, 1, 1, Qt::AlignLeft); d->htmlName = new QLineEdit(this); d->htmlName->setMaxLength(13); // Qt's QColor allows 12 hexa-digits d->htmlName->setText("#FFFFFF"); // But HTML uses only 6, so do not worry about the size w = d->htmlName->fontMetrics().width(QLatin1String("#DDDDDDD")); d->htmlName->setFixedWidth(w); l_grid->addWidget(d->htmlName, 1, 2, Qt::AlignLeft); connect(d->htmlName, SIGNAL(textChanged(const QString &)), SLOT(slotHtmlChanged())); d->patch = new KColorPatch(this); d->patch->setFixedSize(48, 48); l_grid->addWidget(d->patch, 0, 0, 2, 1, Qt::AlignHCenter | Qt::AlignVCenter); connect(d->patch, SIGNAL(colorChanged(const QColor&)), SLOT(setColor(const QColor&))); tl_layout->activate(); readSettings(); d->bRecursion = false; d->bEditHsv = false; d->bEditRgb = false; d->bEditHtml = false; setFixedSize(sizeHint()); QColor col; col.setHsv(0, 0, 255); d->_setColor(col); // FIXME: with enabled event filters, it crashes after ever enter of a drag. // better disable drag and drop than crashing it... // d->htmlName->installEventFilter(this); // d->hsSelector->installEventFilter(this); d->hsSelector->setAcceptDrops(true); d->setVMode(); }
KColorDialog::KColorDialog( TQWidget *parent, const char *name, bool modal ) :KDialogBase( parent, name, modal, i18n("Select Color"), modal ? Ok|Cancel : Close, Ok, true ) { d = new KColorDialogPrivate; d->bRecursion = true; d->bColorPicking = false; #ifdef Q_WS_X11 d->oldfilter = 0; #endif d->cbDefaultColor = 0L; connect( this, TQT_SIGNAL(okClicked(void)),this,TQT_SLOT(slotWriteSettings(void))); connect( this, TQT_SIGNAL(closeClicked(void)),this,TQT_SLOT(slotWriteSettings(void))); TQLabel *label; // // Create the top level page and its layout // TQWidget *page = new TQWidget( this ); setMainWidget( page ); TQGridLayout *tl_layout = new TQGridLayout( page, 3, 3, 0, spacingHint() ); d->tl_layout = tl_layout; tl_layout->addColSpacing( 1, spacingHint() * 2 ); // // the more complicated part: the left side // add a V-box // TQVBoxLayout *l_left = new TQVBoxLayout(); tl_layout->addLayout(l_left, 0, 0); // // add a H-Box for the XY-Selector and a grid for the // entry fields // TQHBoxLayout *l_ltop = new TQHBoxLayout(); l_left->addLayout(l_ltop); // a little space between l_left->addSpacing(10); TQGridLayout *l_lbot = new TQGridLayout(3, 6); l_left->addLayout(TQT_TQLAYOUT(l_lbot)); // // the palette and value selector go into the H-box // d->hsSelector = new KHSSelector( page ); d->hsSelector->setMinimumSize(140, 70); l_ltop->addWidget(d->hsSelector, 8); connect( d->hsSelector, TQT_SIGNAL( valueChanged( int, int ) ), TQT_SLOT( slotHSChanged( int, int ) ) ); d->valuePal = new KValueSelector( page ); d->valuePal->setMinimumSize(26, 70); l_ltop->addWidget(d->valuePal, 1); connect( d->valuePal, TQT_SIGNAL( valueChanged( int ) ), TQT_SLOT( slotVChanged( int ) ) ); // // add the HSV fields // label = new TQLabel( i18n("H:"), page ); label->setAlignment(AlignRight | AlignVCenter); l_lbot->addWidget(label, 0, 2); d->hedit = new KColorSpinBox( 0, 359, 1, page ); d->hedit->setValidator( new TQIntValidator( TQT_TQOBJECT(d->hedit) ) ); l_lbot->addWidget(d->hedit, 0, 3); connect( d->hedit, TQT_SIGNAL( valueChanged(int) ), TQT_SLOT( slotHSVChanged() ) ); label = new TQLabel( i18n("S:"), page ); label->setAlignment(AlignRight | AlignVCenter); l_lbot->addWidget(label, 1, 2); d->sedit = new KColorSpinBox( 0, 255, 1, page ); d->sedit->setValidator( new TQIntValidator( TQT_TQOBJECT(d->sedit) ) ); l_lbot->addWidget(d->sedit, 1, 3); connect( d->sedit, TQT_SIGNAL( valueChanged(int) ), TQT_SLOT( slotHSVChanged() ) ); label = new TQLabel( i18n("V:"), page ); label->setAlignment(AlignRight | AlignVCenter); l_lbot->addWidget(label, 2, 2); d->vedit = new KColorSpinBox( 0, 255, 1, page ); d->vedit->setValidator( new TQIntValidator( TQT_TQOBJECT(d->vedit) ) ); l_lbot->addWidget(d->vedit, 2, 3); connect( d->vedit, TQT_SIGNAL( valueChanged(int) ), TQT_SLOT( slotHSVChanged() ) ); // // add the RGB fields // label = new TQLabel( i18n("R:"), page ); label->setAlignment(AlignRight | AlignVCenter); l_lbot->addWidget(label, 0, 4); d->redit = new KColorSpinBox( 0, 255, 1, page ); d->redit->setValidator( new TQIntValidator( TQT_TQOBJECT(d->redit) ) ); l_lbot->addWidget(d->redit, 0, 5); connect( d->redit, TQT_SIGNAL( valueChanged(int) ), TQT_SLOT( slotRGBChanged() ) ); label = new TQLabel( i18n("G:"), page ); label->setAlignment(AlignRight | AlignVCenter); l_lbot->addWidget( label, 1, 4); d->gedit = new KColorSpinBox( 0, 255,1, page ); d->gedit->setValidator( new TQIntValidator( TQT_TQOBJECT(d->gedit) ) ); l_lbot->addWidget(d->gedit, 1, 5); connect( d->gedit, TQT_SIGNAL( valueChanged(int) ), TQT_SLOT( slotRGBChanged() ) ); label = new TQLabel( i18n("B:"), page ); label->setAlignment(AlignRight | AlignVCenter); l_lbot->addWidget(label, 2, 4); d->bedit = new KColorSpinBox( 0, 255, 1, page ); d->bedit->setValidator( new TQIntValidator( TQT_TQOBJECT(d->bedit) ) ); l_lbot->addWidget(d->bedit, 2, 5); connect( d->bedit, TQT_SIGNAL( valueChanged(int) ), TQT_SLOT( slotRGBChanged() ) ); // // the entry fields should be wide enough to hold 8888888 // int w = d->hedit->fontMetrics().width("8888888"); d->hedit->setFixedWidth(w); d->sedit->setFixedWidth(w); d->vedit->setFixedWidth(w); d->redit->setFixedWidth(w); d->gedit->setFixedWidth(w); d->bedit->setFixedWidth(w); // // add a layout for the right side // d->l_right = new TQVBoxLayout; tl_layout->addLayout(d->l_right, 0, 2); // // Add the palette table // d->table = new KPaletteTable( page ); d->l_right->addWidget(d->table, 10); connect( d->table, TQT_SIGNAL( colorSelected( const TQColor &, const TQString & ) ), TQT_SLOT( slotColorSelected( const TQColor &, const TQString & ) ) ); connect( d->table, TQT_SIGNAL( colorDoubleClicked( const TQColor &, const TQString & ) ), TQT_SLOT( slotColorDoubleClicked( const TQColor &, const TQString & ) ) ); // Store the default value for saving time. d->originalPalette = d->table->palette(); // // a little space between // d->l_right->addSpacing(10); TQHBoxLayout *l_hbox = new TQHBoxLayout( d->l_right ); // // The add to custom colors button // TQPushButton *button = new TQPushButton( page ); button->setText(i18n("&Add to Custom Colors")); l_hbox->addWidget(button, 0, AlignLeft); connect( button, TQT_SIGNAL( clicked()), TQT_SLOT( slotAddToCustomColors())); // // The color picker button // button = new TQPushButton( page ); button->setPixmap( BarIcon("colorpicker")); l_hbox->addWidget(button, 0, AlignHCenter ); connect( button, TQT_SIGNAL( clicked()), TQT_SLOT( slotColorPicker())); // // a little space between // d->l_right->addSpacing(10); // // and now the entry fields and the patch (=colored box) // TQGridLayout *l_grid = new TQGridLayout( d->l_right, 2, 3); l_grid->setColStretch(2, 1); label = new TQLabel( page ); label->setText(i18n("Name:")); l_grid->addWidget(TQT_TQWIDGET(label), 0, 1, Qt::AlignLeft); d->colorName = new TQLabel( page ); l_grid->addWidget(TQT_TQWIDGET(d->colorName), 0, 2, Qt::AlignLeft); label = new TQLabel( page ); label->setText(i18n("HTML:")); l_grid->addWidget(TQT_TQWIDGET(label), 1, 1, Qt::AlignLeft); d->htmlName = new KLineEdit( page ); d->htmlName->setMaxLength( 13 ); // Qt's TQColor allows 12 hexa-digits d->htmlName->setText("#FFFFFF"); // But HTML uses only 6, so do not worry about the size w = d->htmlName->fontMetrics().width(TQString::fromLatin1("#DDDDDDD")); d->htmlName->setFixedWidth(w); l_grid->addWidget(TQT_TQWIDGET(d->htmlName), 1, 2, Qt::AlignLeft); connect( d->htmlName, TQT_SIGNAL( textChanged(const TQString &) ), TQT_SLOT( slotHtmlChanged() ) ); d->patch = new KColorPatch( page ); d->patch->setFixedSize(48, 48); l_grid->addMultiCellWidget(TQT_TQWIDGET(d->patch), 0, 1, 0, 0, Qt::AlignHCenter | Qt::AlignVCenter); connect( d->patch, TQT_SIGNAL( colorChanged( const TQColor&)), TQT_SLOT( setColor( const TQColor&))); tl_layout->activate(); page->setMinimumSize( page->sizeHint() ); readSettings(); d->bRecursion = false; d->bEditHsv = false; d->bEditRgb = false; d->bEditHtml = false; disableResize(); KColor col; col.setHsv( 0, 0, 255 ); _setColor( col ); d->htmlName->installEventFilter(this); d->hsSelector->installEventFilter(this); d->hsSelector->setAcceptDrops(true); }