• Skip to content
  • Skip to link menu
KDE 4.1 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

Konsole

ColorSchemeEditor.cpp

Go to the documentation of this file.
00001 /*
00002     Copyright 2007-2008 by Robert Knight <robertknight@gmail.com>
00003 
00004     This program is free software; you can redistribute it and/or modify
00005     it under the terms of the GNU General Public License as published by
00006     the Free Software Foundation; either version 2 of the License, or
00007     (at your option) any later version.
00008 
00009     This program is distributed in the hope that it will be useful,
00010     but WITHOUT ANY WARRANTY; without even the implied warranty of
00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012     GNU General Public License for more details.
00013 
00014     You should have received a copy of the GNU General Public License
00015     along with this program; if not, write to the Free Software
00016     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00017     02110-1301  USA.
00018 */
00019 
00020 // Own
00021 #include "ColorSchemeEditor.h"
00022 
00023 // Qt
00024 #include <QtGui/QBrush>
00025 #include <QtGui/QFontMetrics>
00026 #include <QtGui/QHeaderView>
00027 #include <QtGui/QItemDelegate>
00028 #include <QtGui/QItemEditorCreator>
00029 
00030 // KDE
00031 #include <KColorDialog>
00032 #include <KDebug>
00033 #include <KWindowSystem>
00034 
00035 // Konsole
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     // description edit
00064     connect( _ui->descriptionEdit , SIGNAL(textChanged(const QString&)) , this , 
00065             SLOT(setDescription(const QString&)) );
00066 
00067     // transparency slider
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     // randomized background
00074     connect( _ui->randomizedBackgroundCheck , SIGNAL(toggled(bool)) , this , 
00075              SLOT(setRandomizedBackgroundColor(bool)) );
00076 
00077     // color table
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     // warning label when transparency is not available
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     // ignore if this is not a color column
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     // setup description edit
00158     _ui->descriptionEdit->setText(_colors->description());
00159 
00160     // setup color table
00161     setupColorTable(_colors);
00162 
00163     // setup transparency slider
00164     const int transparencyPercent = (int) ( (1-_colors->opacity())*100 );
00165     
00166     _ui->transparencySlider->setValue(transparencyPercent);
00167     setTransparencyPercentLabel(transparencyPercent);
00168 
00169     // randomized background color checkbox
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     // ensure that color names are as fully visible as possible
00189     _ui->colorTable->resizeColumnToContents(0);
00190 }
00191 ColorScheme* ColorSchemeEditor::colorScheme() const
00192 {
00193     return _colors;
00194 }
00195 
00196 #include "ColorSchemeEditor.moc"

Konsole

Skip menu "Konsole"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

API Reference

Skip menu "API Reference"
  • Konsole
  • Libraries
  •   libkonq
Generated for API Reference by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal