Konsole
ColorSchemeEditor.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "ColorSchemeEditor.h"
00022
00023
00024 #include <QtGui/QBrush>
00025 #include <QtGui/QFontMetrics>
00026 #include <QtGui/QHeaderView>
00027 #include <QtGui/QItemDelegate>
00028 #include <QtGui/QItemEditorCreator>
00029
00030
00031 #include <KColorDialog>
00032 #include <KDebug>
00033 #include <KWindowSystem>
00034
00035
00036 #include "ui_ColorSchemeEditor.h"
00037 #include "CharacterColor.h"
00038
00039 using namespace Konsole;
00040
00041 #if 0
00042 class ColorEditorCreator : public QItemEditorCreatorBase
00043 {
00044 virtual QWidget* createWidget(QWidget* parent) const
00045 {
00046 return new KColorButton(parent);
00047 }
00048
00049 virtual QByteArray valuePropertyName() const
00050 {
00051 return QByteArray("color");
00052 }
00053 };
00054 #endif
00055
00056 ColorSchemeEditor::ColorSchemeEditor(QWidget* parent)
00057 : QWidget(parent)
00058 , _colors(0)
00059 {
00060 _ui = new Ui::ColorSchemeEditor();
00061 _ui->setupUi(this);
00062
00063
00064 connect( _ui->descriptionEdit , SIGNAL(textChanged(const QString&)) , this ,
00065 SLOT(setDescription(const QString&)) );
00066
00067
00068 QFontMetrics metrics(font());
00069 _ui->transparencyPercentLabel->setMinimumWidth( metrics.width("100%") );
00070
00071 connect( _ui->transparencySlider , SIGNAL(valueChanged(int)) , this , SLOT(setTransparencyPercentLabel(int)) );
00072
00073
00074 connect( _ui->randomizedBackgroundCheck , SIGNAL(toggled(bool)) , this ,
00075 SLOT(setRandomizedBackgroundColor(bool)) );
00076
00077
00078 _ui->colorTable->setColumnCount(2);
00079 _ui->colorTable->setRowCount(TABLE_COLORS);
00080
00081 QStringList labels;
00082 labels << i18n("Name") << i18n("Color");
00083 _ui->colorTable->setHorizontalHeaderLabels(labels);
00084
00085 _ui->colorTable->horizontalHeader()->setStretchLastSection(true);
00086
00087 QTableWidgetItem* item = new QTableWidgetItem("Test");
00088 _ui->colorTable->setItem(0,0,item);
00089
00090 _ui->colorTable->verticalHeader()->hide();
00091
00092 connect( _ui->colorTable , SIGNAL(itemClicked(QTableWidgetItem*)) , this ,
00093 SLOT(editColorItem(QTableWidgetItem*)) );
00094
00095
00096 if ( KWindowSystem::compositingActive() )
00097 {
00098 _ui->transparencyWarningWidget->setVisible(false);
00099 }
00100 else
00101 {
00102 _ui->transparencyWarningWidget->setText(i18n("The background transparency setting will not"
00103 " be used because your desktop does not appear to support"
00104 " transparent windows."));
00105 }
00106 }
00107 void ColorSchemeEditor::setRandomizedBackgroundColor( bool randomize )
00108 {
00109 _colors->setRandomizedBackgroundColor(randomize);
00110 }
00111 ColorSchemeEditor::~ColorSchemeEditor()
00112 {
00113 delete _colors;
00114 delete _ui;
00115 }
00116 void ColorSchemeEditor::editColorItem( QTableWidgetItem* item )
00117 {
00118
00119 if ( item->column() != 1 )
00120 return;
00121
00122 KColorDialog* dialog = new KColorDialog(this);
00123 dialog->setColor( item->background().color() );
00124
00125 dialog->exec();
00126
00127 item->setBackground( dialog->color() );
00128
00129 ColorEntry entry(_colors->colorEntry(item->row()));
00130 entry.color = dialog->color();
00131 _colors->setColorTableEntry(item->row(),entry);
00132
00133 emit colorsChanged(_colors);
00134 }
00135 void ColorSchemeEditor::setDescription(const QString& text)
00136 {
00137 if ( _colors )
00138 _colors->setDescription(text);
00139
00140 if ( _ui->descriptionEdit->text() != text )
00141 _ui->descriptionEdit->setText(text);
00142 }
00143 void ColorSchemeEditor::setTransparencyPercentLabel(int percent)
00144 {
00145 _ui->transparencyPercentLabel->setText( QString("%1%").arg(percent) );
00146
00147 qreal opacity = ( 100.0 - percent ) / 100.0;
00148 _colors->setOpacity(opacity);
00149 }
00150 void ColorSchemeEditor::setup(const ColorScheme* scheme)
00151 {
00152 if ( _colors )
00153 delete _colors;
00154
00155 _colors = new ColorScheme(*scheme);
00156
00157
00158 _ui->descriptionEdit->setText(_colors->description());
00159
00160
00161 setupColorTable(_colors);
00162
00163
00164 const int transparencyPercent = (int) ( (1-_colors->opacity())*100 );
00165
00166 _ui->transparencySlider->setValue(transparencyPercent);
00167 setTransparencyPercentLabel(transparencyPercent);
00168
00169
00170 _ui->randomizedBackgroundCheck->setChecked( scheme->randomizedBackgroundColor() );
00171 }
00172 void ColorSchemeEditor::setupColorTable(const ColorScheme* colors)
00173 {
00174 ColorEntry table[TABLE_COLORS];
00175 colors->getColorTable(table);
00176
00177 for ( int row = 0 ; row < TABLE_COLORS ; row++ )
00178 {
00179 QTableWidgetItem* nameItem = new QTableWidgetItem( ColorScheme::translatedColorNameForIndex(row) );
00180 QTableWidgetItem* colorItem = new QTableWidgetItem();
00181 colorItem->setBackground( table[row].color );
00182 colorItem->setFlags( colorItem->flags() & ~Qt::ItemIsEditable & ~Qt::ItemIsSelectable );
00183
00184 _ui->colorTable->setItem(row,0,nameItem);
00185 _ui->colorTable->setItem(row,1,colorItem);
00186 }
00187
00188
00189 _ui->colorTable->resizeColumnToContents(0);
00190 }
00191 ColorScheme* ColorSchemeEditor::colorScheme() const
00192 {
00193 return _colors;
00194 }
00195
00196 #include "ColorSchemeEditor.moc"