1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256
|
/***************************************************************************
* Copyright (C) 2004-2005 by Adam Jakubek <mig21@static.int.pl> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include "../config.h"
#include <qcheckbox.h>
#include <qcolordialog.h>
#include <qcombobox.h>
#include <qlabel.h>
#include <qmessagebox.h>
#include <qpushbutton.h>
#include <qradiobutton.h>
#include <qsettings.h>
#include <qslider.h>
#include "MainForm.h"
MainForm::MainForm() : MainFormBase(0, 0, false,
WStyle_Customize | WStyle_NormalBorder | WStyle_Title |
WStyle_SysMenu | WStyle_Minimize)
{
#ifndef HAVE_XRENDER
comboBox1->removeItem(3);
#endif
readSettings();
// override state changes
isModified = false;
}
MainForm::~MainForm()
{
}
void MainForm::engineChange(int index)
{
if (!index)
slider1->setEnabled(false);
else
slider1->setEnabled(true);
setModified();
}
void MainForm::opacityChange(int opacity)
{
if (opacity < 0)
opacity = 0;
else if (opacity > 100)
opacity = 100;
QString str = QString::number(opacity) + "%";
textLabel4->setText(str);
}
void MainForm::setModified()
{
isModified = true;
}
void MainForm::customOverHighlight()
{
QColor col =
QColorDialog::getColor(pushButton1->paletteBackgroundColor(), this);
if (col.isValid())
pushButton1->setPaletteBackgroundColor(col);
setModified();
}
void MainForm::customFocusHighlight()
{
QColor col =
QColorDialog::getColor(pushButton2->paletteBackgroundColor(), this);
if (col.isValid())
pushButton2->setPaletteBackgroundColor(col);
setModified();
}
void MainForm::customCheckMarkColor()
{
QColor col =
QColorDialog::getColor(pushButton3->paletteBackgroundColor(), this);
if (col.isValid())
pushButton3->setPaletteBackgroundColor(col);
setModified();
}
void MainForm::closeEvent(QCloseEvent *e)
{
if (isModified)
{
int sel = QMessageBox::question(this, tr("Polymer configuration"),
tr("Do you wish to save settings before quitting?"),
tr("&Yes"), tr("&No"), tr("&Cancel"), 0, 2);
switch (sel)
{
case 0:
if (!writeSettings())
QMessageBox::warning(this, tr("Polymer configuration"),
tr("Failed to save settings"), QMessageBox::Ok, QMessageBox::NoButton);
// fall through intended
case 1:
e->accept();
break;
}
}
else
e->accept();
}
void MainForm::readSettings()
{
QSettings s;
// Polymer specific settings
s.beginGroup("/polymerstyle/Settings");
if (!s.readBoolEntry("/scrollBarLines", false))
radioButton1->setChecked(true);
else
radioButton2->setChecked(true);
checkBox1->setChecked(s.readBoolEntry("/animateProgressBar", false));
checkBox2->setChecked(s.readBoolEntry("/drawToolBarSeparator", true));
checkBox3->setChecked(s.readBoolEntry("/drawToolBarItemSeparator", true));
checkBox4->setChecked(s.readBoolEntry("/drawFocusRect", true));
checkBox5->setChecked(s.readBoolEntry("/drawTriangularExpander", false));
checkBox6->setChecked(s.readBoolEntry("/inputFocusHighlight", true));
checkBox7->setChecked(s.readBoolEntry("/customOverHighlightColor", false));
if (!checkBox7->isChecked())
pushButton1->setEnabled(false);
QColor over(s.readEntry("/overHighlightColor", "black"));
if (!over.isValid())
over.setNamedColor("black");
pushButton1->setPaletteBackgroundColor(over);
checkBox8->setChecked(s.readBoolEntry("/customFocusHighlightColor", false));
if (!checkBox8->isChecked())
pushButton2->setEnabled(false);
QColor focus(s.readEntry("/focusHighlightColor", "black"));
if (!focus.isValid())
focus.setNamedColor("black");
pushButton2->setPaletteBackgroundColor(focus);
checkBox9->setChecked(s.readBoolEntry("/customCheckMarkColor", false));
if (!checkBox9->isChecked())
pushButton3->setEnabled(false);
QColor checkmark(s.readEntry("/checkMarkColor", "black"));
if (!checkmark.isValid())
checkmark.setNamedColor("black");
pushButton3->setPaletteBackgroundColor(checkmark);
s.endGroup();
// KStyle specific settings
QString engine = s.readEntry("/KStyle/Settings/MenuTransparencyEngine", "Disabled");
if (engine == "SoftwareTint")
comboBox1->setCurrentItem(1);
else if (engine == "SoftwareBlend")
comboBox1->setCurrentItem(2);
else if (engine == "XRender")
#ifdef HAVE_XRENDER
comboBox1->setCurrentItem(3);
#else
comboBox1->setCurrentItem(2);
#endif
else
comboBox1->setCurrentItem(0);
if (!comboBox1->currentItem())
slider1->setEnabled(false);
else
slider1->setEnabled(true);
int opacity = static_cast<int>(s.readDoubleEntry("/KStyle/Settings/MenuOpacity", 0.90) * 100);
if (opacity < 0)
opacity = 0;
else if (opacity > 100)
opacity = 100;
slider1->setValue(opacity);
checkBox10->setChecked(s.readBoolEntry("/KStyle/Settings/MenuDropShadow", false));
}
bool MainForm::writeSettings()
{
QSettings s;
bool ok = true;
// Polymer specific settings
s.beginGroup("/polymerstyle/Settings");
ok = s.writeEntry("/scrollBarLines", !radioButton1->isChecked()) && ok;
ok = s.writeEntry("/animateProgressBar", checkBox1->isChecked()) && ok;
ok = s.writeEntry("/drawToolBarSeparator", checkBox2->isChecked()) && ok;
ok = s.writeEntry("/drawToolBarItemSeparator", checkBox3->isChecked()) && ok;
ok = s.writeEntry("/drawFocusRect", checkBox4->isChecked()) && ok;
ok = s.writeEntry("/drawTriangularExpander", checkBox5->isChecked()) && ok;
ok = s.writeEntry("/inputFocusHighlight", checkBox6->isChecked()) && ok;
ok = s.writeEntry("/customOverHighlightColor", checkBox7->isChecked()) && ok;
QColor over = pushButton1->paletteBackgroundColor();
if (!over.isValid())
over.setNamedColor("black");
ok = s.writeEntry("/overHighlightColor", over.name()) && ok;
ok = s.writeEntry("/customFocusHighlightColor", checkBox8->isChecked()) && ok;
QColor focus = pushButton2->paletteBackgroundColor();
if (!focus.isValid())
focus.setNamedColor("black");
ok = s.writeEntry("/focusHighlightColor", focus.name()) && ok;
ok = s.writeEntry("/customCheckMarkColor", checkBox9->isChecked()) && ok;
QColor checkmark = pushButton3->paletteBackgroundColor();
if (!checkmark.isValid())
checkmark.setNamedColor("black");
ok = s.writeEntry("/checkMarkColor", checkmark.name()) && ok;
s.endGroup();
// KStyle specific settings
QString str;
switch (comboBox1->currentItem())
{
case 1:
str = "SoftwareTint";
break;
case 2:
str = "SoftwareBlend";
break;
case 3:
#ifdef HAVE_XRENDER
str = "XRender";
#else
str = "SoftwareBlend";
#endif
break;
default:
str = "Disabled";
break;
}
ok = s.writeEntry("/KStyle/Settings/MenuTransparencyEngine", str) && ok;
double opacity = slider1->value() / 100.0;
if (opacity < 0.0)
opacity = 0.0;
else if (opacity > 1.0)
opacity = 1.0;
ok = s.writeEntry("/KStyle/Settings/MenuOpacity", opacity) && ok;
ok = s.writeEntry("/KStyle/Settings/MenuDropShadow", checkBox10->isChecked()) && ok;
return ok;
}
|