24 #include <QtGui/QFontMetrics>
25 #include <QtCore/QFileInfo>
28 #include <KColorDialog>
29 #include <KWindowSystem>
30 #include <KFileDialog>
31 #include <KUrlCompletion>
34 #include "ui_ColorSchemeEditor.h"
38 using namespace Konsole;
54 setButtons(KDialog::Ok | KDialog::Cancel | KDialog::Apply);
55 connect(
this, SIGNAL(applyClicked()),
this, SLOT(saveColorScheme()));
56 connect(
this, SIGNAL(okClicked()),
this, SLOT(saveColorScheme()));
59 _ui =
new Ui::ColorSchemeEditor();
60 _ui->setupUi(mainWidget());
63 _ui->descriptionEdit->setClearButtonShown(
true);
64 connect(_ui->descriptionEdit , SIGNAL(textChanged(QString)) ,
this ,
68 QFontMetrics metrics(font());
69 _ui->transparencyPercentLabel->setMinimumWidth(metrics.width(
"100%"));
71 connect(_ui->transparencySlider , SIGNAL(valueChanged(
int)) ,
this , SLOT(setTransparencyPercentLabel(
int)));
74 connect(_ui->randomizedBackgroundCheck , SIGNAL(toggled(
bool)) ,
this ,
75 SLOT(setRandomizedBackgroundColor(
bool)));
78 KUrlCompletion* fileCompletion =
new KUrlCompletion(KUrlCompletion::FileCompletion);
79 fileCompletion->setParent(
this);
80 _ui->wallpaperPath->setCompletionObject(fileCompletion);
81 _ui->wallpaperPath->setClearButtonShown(
true);
82 _ui->wallpaperSelectButton->setIcon(KIcon(
"image-x-generic"));
84 connect(_ui->wallpaperSelectButton, SIGNAL(clicked()),
85 this, SLOT(selectWallpaper()));
86 connect(_ui->wallpaperPath, SIGNAL(textChanged(QString)),
87 this, SLOT(wallpaperPathChanged(QString)));
90 _ui->colorTable->setColumnCount(3);
94 labels << i18nc(
"@label:listbox Column header text for color names",
"Name")
95 << i18nc(
"@label:listbox Column header text for the actual colors",
"Color")
96 << i18nc(
"@label:listbox Column header text for the actual intense colors",
"Intense color");
97 _ui->colorTable->setHorizontalHeaderLabels(labels);
100 _ui->colorTable->horizontalHeader()->setResizeMode(
NAME_COLUMN, QHeaderView::ResizeToContents);
101 _ui->colorTable->horizontalHeader()->setResizeMode(
COLOR_COLUMN, QHeaderView::Stretch);
104 QTableWidgetItem* item =
new QTableWidgetItem(
"Test");
105 _ui->colorTable->setItem(0, 0, item);
107 _ui->colorTable->verticalHeader()->hide();
109 connect(_ui->colorTable , SIGNAL(itemClicked(QTableWidgetItem*)) ,
this ,
110 SLOT(editColorItem(QTableWidgetItem*)));
113 _ui->transparencyWarningWidget->setWordWrap(
true);
114 _ui->transparencyWarningWidget->setCloseButtonVisible(
false);
115 _ui->transparencyWarningWidget->setMessageType(KMessageWidget::Warning);
117 if (KWindowSystem::compositingActive()) {
118 _ui->transparencyWarningWidget->setVisible(
false);
120 _ui->transparencyWarningWidget->setText(i18nc(
"@info:status",
121 "The background transparency setting will not"
122 " be used because your desktop does not appear to support"
123 " transparent windows."));
131 void ColorSchemeEditor::editColorItem(QTableWidgetItem* item)
138 QColor color = item->background().color();
139 int result = KColorDialog::getColor(color);
141 if (result == KColorDialog::Accepted) {
142 item->setBackground(color);
144 int colorSchemeRow = item->row();
157 void ColorSchemeEditor::selectWallpaper()
159 const KUrl url = KFileDialog::getImageOpenUrl(_ui->wallpaperPath->text(),
161 i18nc(
"@action:button",
"Select wallpaper image file"));
164 _ui->wallpaperPath->setText(url.path());
166 void ColorSchemeEditor::wallpaperPathChanged(
const QString& path)
168 if (path.isEmpty()) {
173 if (i.exists() && i.isFile() && i.isReadable())
182 if (_ui->descriptionEdit->text() != text)
183 _ui->descriptionEdit->setText(text);
185 void ColorSchemeEditor::setTransparencyPercentLabel(
int percent)
187 _ui->transparencyPercentLabel->setText(QString(
"%1%").arg(percent));
189 const qreal opacity = (100.0 - percent) / 100.0;
192 void ColorSchemeEditor::setRandomizedBackgroundColor(
bool randomize)
205 setCaption(i18n(
"New Color Scheme"));
208 setCaption(i18n(
"Edit Color Scheme"));
212 _ui->descriptionEdit->setText(_colors->
description());
215 setupColorTable(_colors);
218 const int transparencyPercent = qRound((1 - _colors->
opacity()) * 100);
219 _ui->transparencySlider->setValue(transparencyPercent);
220 setTransparencyPercentLabel(transparencyPercent);
226 _ui->wallpaperPath->setText(scheme->
wallpaper()->path());
228 void ColorSchemeEditor::setupColorTable(
const ColorScheme* colors)
235 nameItem->setFlags(nameItem->flags() & ~Qt::ItemIsEditable);
237 QTableWidgetItem* colorItem =
new QTableWidgetItem();
238 colorItem->setBackground(table[row].color);
239 colorItem->setFlags(colorItem->flags() & ~Qt::ItemIsEditable & ~Qt::ItemIsSelectable);
240 colorItem->setToolTip(i18nc(
"@info:tooltip",
"Click to choose color"));
242 QTableWidgetItem* colorItemIntense =
new QTableWidgetItem();
243 colorItemIntense->setBackground(table[COLOR_TABLE_ROW_LENGTH + row].color);
244 colorItemIntense->setFlags(colorItem->flags() & ~Qt::ItemIsEditable & ~Qt::ItemIsSelectable);
245 colorItemIntense->setToolTip(i18nc(
"@info:tooltip",
"Click to choose intense color"));
247 _ui->colorTable->setItem(row,
NAME_COLUMN, nameItem);
252 _ui->colorTable->resizeColumnToContents(0);
255 _ui->colorTable->setFixedHeight(_ui->colorTable->verticalHeader()->length() + _ui->colorTable->horizontalHeader()->height() + 2);
266 void ColorSchemeEditor::saveColorScheme()
271 #include "ColorSchemeEditor.moc"
static QString translatedColorNameForIndex(int index)
virtual ~ColorSchemeEditor()
void getColorTable(ColorEntry *table, uint randomSeed=0) const
Copies the color entries which form the palette for this color scheme into table. ...
void setRandomizedBackgroundColor(bool randomize)
Enables randomization of the background color.
void setOpacity(qreal opacity)
Sets the opacity level of the display background.
ColorEntry colorEntry(int index, uint randomSeed=0) const
Retrieves a single color entry from the table.
qreal opacity() const
Returns the opacity level for this color scheme, see setOpacity() TODO: More documentation.
bool randomizedBackgroundColor() const
Returns true if the background color is randomized.
An entry in a terminal display's color palette.
void setColorTableEntry(int index, const ColorEntry &entry)
Sets a single entry within the color palette.
void setup(const ColorScheme *scheme, bool isNewScheme)
Initializes the dialog with the properties of the specified color scheme.
ColorScheme & colorScheme() const
Returns the modified color scheme.
QString description() const
Returns the descriptive name of the color scheme.
void setDescription(const QString &description)
Sets the descriptive name of the color scheme.
void colorSchemeSaveRequested(const ColorScheme &scheme, bool isNewScheme)
Used to send back colorscheme changes into the profile edited.
ColorSchemeEditor(QWidget *parent=0)
Constructs a new color scheme editor with the specified parent.
void colorsChanged(ColorScheme *scheme)
Emitted when the colors in the color scheme change.
const int INTENSE_COLOR_COLUMN
void setWallpaper(const QString &path)
QColor color
The color value of this entry for display.
const int COLOR_TABLE_ROW_LENGTH
Represents a color scheme for a terminal display.
void setDescription(const QString &description)
Sets the text displayed in the description edit field.
ColorSchemeWallpaper::Ptr wallpaper() const