[kde-doc-english] [konsole] src: ColorScheme dialog improvements - extra column for intense colors

Kurt Hindenburg kurt.hindenburg at gmail.com
Tue May 7 15:56:08 UTC 2013


Git commit 1c3a87bf5f38b0cf43eafe535d1c0ac15d55f611 by Kurt Hindenburg.
Committed on 07/05/2013 at 17:47.
Pushed by hindenburg into branch 'master'.

ColorScheme dialog improvements - extra column for intense colors

Add extra column for intense colors so each color and the corresponding
intense color is side by side (the data model colorScheme is unchanged,
only the ui has the additional column)
Also adjust the GUI such that there are no scrollbars for the table. The
EditProfileDialog is still larger.

Patch by renan fargetton renan.fargetton at gmail.com
with minor edits by me
>From review 110318
CCMAIL: renan.fargetton at gmail.com
GUI:

M  +39   -14   src/ColorSchemeEditor.cpp

http://commits.kde.org/konsole/1c3a87bf5f38b0cf43eafe535d1c0ac15d55f611

diff --git a/src/ColorSchemeEditor.cpp b/src/ColorSchemeEditor.cpp
index e75cacb..421f613 100644
--- a/src/ColorSchemeEditor.cpp
+++ b/src/ColorSchemeEditor.cpp
@@ -37,6 +37,14 @@
 
 using namespace Konsole;
 
+// colorTable is half the length of _table in ColorScheme class
+// since intense colors are in a separated column
+const int COLOR_TABLE_ROW_LENGTH =  TABLE_COLORS / 2; 
+
+const int NAME_COLUMN = 0;           // column 0 : color names
+const int COLOR_COLUMN = 1;          // column 1 : actual colors
+const int INTENSE_COLOR_COLUMN = 2;  // column 2 : intense colors
+
 ColorSchemeEditor::ColorSchemeEditor(QWidget* aParent)
     : QWidget(aParent)
     , _colors(0)
@@ -72,14 +80,19 @@ ColorSchemeEditor::ColorSchemeEditor(QWidget* aParent)
             this, SLOT(wallpaperPathChanged(QString)));
 
     // color table
-    _ui->colorTable->setColumnCount(2);
-    _ui->colorTable->setRowCount(TABLE_COLORS);
+    _ui->colorTable->setColumnCount(3);
+    _ui->colorTable->setRowCount(COLOR_TABLE_ROW_LENGTH);
 
     QStringList labels;
-    labels << i18nc("@label:listbox Column header text for color names", "Name") << i18nc("@label:listbox Column header text for the actual colors", "Color");
+    labels << i18nc("@label:listbox Column header text for color names", "Name")
+           << i18nc("@label:listbox Column header text for the actual colors", "Color")
+           << i18nc("@label:listbox Column header text for the actual intense colors", "Intense color");
     _ui->colorTable->setHorizontalHeaderLabels(labels);
 
-    _ui->colorTable->horizontalHeader()->setStretchLastSection(true);
+    // Set resize mode for colorTable columns
+    _ui->colorTable->horizontalHeader()->setResizeMode(NAME_COLUMN, QHeaderView::ResizeToContents);
+    _ui->colorTable->horizontalHeader()->setResizeMode(COLOR_COLUMN, QHeaderView::Stretch);
+    _ui->colorTable->horizontalHeader()->setResizeMode(INTENSE_COLOR_COLUMN, QHeaderView::Stretch);
 
     QTableWidgetItem* item = new QTableWidgetItem("Test");
     _ui->colorTable->setItem(0, 0, item);
@@ -110,20 +123,23 @@ ColorSchemeEditor::~ColorSchemeEditor()
 }
 void ColorSchemeEditor::editColorItem(QTableWidgetItem* item)
 {
-    const int COLOR_COLUMN = 1;
-
     // ignore if this is not a color column
-    if (item->column() != COLOR_COLUMN)
-        return;
+    if (item->column() != COLOR_COLUMN && item->column() != INTENSE_COLOR_COLUMN)
+        return;	
 
     QColor color = item->background().color();
     int result = KColorDialog::getColor(color);
     if (result == KColorDialog::Accepted) {
         item->setBackground(color);
 
-        ColorEntry entry(_colors->colorEntry(item->row()));
+        int colorSchemeRow = item->row(); 
+        // Intense colors row are in the bottom half of the color table
+        if (item->column() == INTENSE_COLOR_COLUMN)
+            colorSchemeRow += COLOR_TABLE_ROW_LENGTH;
+
+        ColorEntry entry(_colors->colorEntry(colorSchemeRow));
         entry.color = color;
-        _colors->setColorTableEntry(item->row(), entry);
+        _colors->setColorTableEntry(colorSchemeRow, entry);
 
         emit colorsChanged(_colors);
     }
@@ -195,7 +211,7 @@ void ColorSchemeEditor::setupColorTable(const ColorScheme* colors)
     ColorEntry table[TABLE_COLORS];
     colors->getColorTable(table);
 
-    for (int row = 0 ; row < TABLE_COLORS ; row++) {
+    for (int row = 0; row < COLOR_TABLE_ROW_LENGTH; row++) {
         QTableWidgetItem* nameItem = new QTableWidgetItem(ColorScheme::translatedColorNameForIndex(row));
         nameItem->setFlags(nameItem->flags() & ~Qt::ItemIsEditable);
 
@@ -204,13 +220,22 @@ void ColorSchemeEditor::setupColorTable(const ColorScheme* colors)
         colorItem->setFlags(colorItem->flags() & ~Qt::ItemIsEditable & ~Qt::ItemIsSelectable);
         colorItem->setToolTip(i18nc("@info:tooltip", "Click to choose color"));
 
-        _ui->colorTable->setItem(row, 0, nameItem);
-        _ui->colorTable->setItem(row, 1, colorItem);
-    }
+        QTableWidgetItem* colorItemIntense = new QTableWidgetItem();
+        colorItemIntense->setBackground(table[COLOR_TABLE_ROW_LENGTH + row].color);
+        colorItemIntense->setFlags(colorItem->flags() & ~Qt::ItemIsEditable & ~Qt::ItemIsSelectable);
+        colorItemIntense->setToolTip(i18nc("@info:tooltip", "Click to choose intense color"));
 
+        _ui->colorTable->setItem(row, NAME_COLUMN, nameItem);
+        _ui->colorTable->setItem(row, COLOR_COLUMN, colorItem);
+        _ui->colorTable->setItem(row, INTENSE_COLOR_COLUMN, colorItemIntense);
+    }
     // ensure that color names are as fully visible as possible
     _ui->colorTable->resizeColumnToContents(0);
+
+    // set the widget height to the table content
+    _ui->colorTable->setFixedHeight(_ui->colorTable->verticalHeader()->length() + _ui->colorTable->horizontalHeader()->height() + 2);
 }
+
 ColorScheme* ColorSchemeEditor::colorScheme() const
 {
     return _colors;


More information about the kde-doc-english mailing list