mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-06-08 22:52:54 -04:00
New dialog for defining own colors for the private chat window.
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@4150 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
eed8ccd1df
commit
0fbde70e32
16 changed files with 1957 additions and 934 deletions
161
retroshare-gui/src/gui/style/StyleDialog.cpp
Normal file
161
retroshare-gui/src/gui/style/StyleDialog.cpp
Normal file
|
@ -0,0 +1,161 @@
|
|||
/****************************************************************
|
||||
*
|
||||
* RetroShare is distributed under the following license:
|
||||
*
|
||||
* Copyright (C) 2006, crypton
|
||||
*
|
||||
* 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., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
****************************************************************/
|
||||
|
||||
#include <QColorDialog>
|
||||
|
||||
#include "gui/settings/rsharesettings.h"
|
||||
|
||||
#include "StyleDialog.h"
|
||||
#include "gui/style/RSStyle.h"
|
||||
|
||||
/** Default constructor */
|
||||
StyleDialog::StyleDialog(RSStyle &style, QWidget *parent, Qt::WFlags flags) : QDialog(parent, flags)
|
||||
{
|
||||
/* Invoke Qt Designer generated QObject setup routine */
|
||||
ui.setupUi(this);
|
||||
|
||||
/* Load window postion */
|
||||
QByteArray geometry = Settings->valueFromGroup("StyleDialog", "Geometry", QByteArray()).toByteArray();
|
||||
if (geometry.isEmpty() == false) {
|
||||
restoreGeometry(geometry);
|
||||
}
|
||||
|
||||
// setWindowIcon(QIcon(":/images/rstray3.png"));
|
||||
|
||||
connect(ui.buttonBox, SIGNAL(accepted()), this, SLOT(onOK()));
|
||||
connect(ui.buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
|
||||
|
||||
connect(ui.color1Button, SIGNAL(clicked()), this, SLOT(chooseColor()));
|
||||
connect(ui.color2Button, SIGNAL(clicked()), this, SLOT(chooseColor()));
|
||||
|
||||
/* Initialize style combobox */
|
||||
ui.styleComboBox->addItem(tr("None"), RSStyle::STYLETYPE_NONE);
|
||||
ui.styleComboBox->addItem(tr("Solid"), RSStyle::STYLETYPE_SOLID);
|
||||
ui.styleComboBox->addItem(tr("Gradient"), RSStyle::STYLETYPE_GRADIENT);
|
||||
|
||||
ui.styleComboBox->setCurrentIndex(style.styleType);
|
||||
connect(ui.styleComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(showButtons()));
|
||||
|
||||
/* Add pushbuttons and labels */
|
||||
pushButtons.append(ui.color1Button);
|
||||
pushButtons.append(ui.color2Button);
|
||||
|
||||
labels.append(ui.color1Label);
|
||||
labels.append(ui.color2Label);
|
||||
|
||||
/* Set pushbuttons visible */
|
||||
showButtons();
|
||||
|
||||
/* Init colors */
|
||||
for (int i = 0; i < pushButtons.size(); i++) {
|
||||
if (i < style.colors.size()) {
|
||||
colors[pushButtons[i]] = style.colors[i];
|
||||
} else {
|
||||
colors[pushButtons[i]] = Qt::white;
|
||||
}
|
||||
}
|
||||
|
||||
drawButtons();
|
||||
drawPreview();
|
||||
}
|
||||
|
||||
/** Destructor. */
|
||||
StyleDialog::~StyleDialog()
|
||||
{
|
||||
/* Save window postion */
|
||||
Settings->setValueToGroup("StyleDialog", "Geometry", saveGeometry());
|
||||
}
|
||||
|
||||
void StyleDialog::onOK()
|
||||
{
|
||||
accept();
|
||||
}
|
||||
|
||||
int StyleDialog::neededColors()
|
||||
{
|
||||
return RSStyle::neededColors((RSStyle::StyleType) ui.styleComboBox->itemData(ui.styleComboBox->currentIndex()).toInt());
|
||||
}
|
||||
|
||||
void StyleDialog::getStyle(RSStyle &style)
|
||||
{
|
||||
style.styleType = (RSStyle::StyleType) ui.styleComboBox->itemData(ui.styleComboBox->currentIndex()).toInt();
|
||||
|
||||
style.colors.clear();
|
||||
|
||||
int count = qMin(neededColors(), pushButtons.size());
|
||||
for (int i = 0; i < count; i++) {
|
||||
style.colors.append(colors[pushButtons[i]]);
|
||||
}
|
||||
}
|
||||
|
||||
void StyleDialog::showButtons()
|
||||
{
|
||||
int count = neededColors();
|
||||
for (int i = 0; i < pushButtons.size(); i++) {
|
||||
pushButtons[i]->setVisible(i < count);
|
||||
labels[i]->setVisible(i < count);
|
||||
}
|
||||
|
||||
drawPreview();
|
||||
}
|
||||
|
||||
void StyleDialog::drawButtons()
|
||||
{
|
||||
QPixmap pxm(16,14);
|
||||
|
||||
QMap<QPushButton*, QColor>::iterator it;
|
||||
for (it = colors.begin(); it != colors.end(); it++) {
|
||||
pxm.fill(it.value());
|
||||
it.key()->setIcon(pxm);
|
||||
}
|
||||
}
|
||||
|
||||
void StyleDialog::drawPreview()
|
||||
{
|
||||
RSStyle style;
|
||||
getStyle(style);
|
||||
|
||||
QString widgetSheet;
|
||||
|
||||
QString styleSheet = style.getStyleSheet();
|
||||
if (styleSheet.isEmpty() == false) {
|
||||
widgetSheet = QString(".QWidget{%1}").arg(styleSheet);
|
||||
}
|
||||
|
||||
ui.previewWidget->setStyleSheet(widgetSheet);
|
||||
}
|
||||
|
||||
void StyleDialog::chooseColor()
|
||||
{
|
||||
QPushButton *button = dynamic_cast<QPushButton*>(sender());
|
||||
if (button == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
QColor color = QColorDialog::getColor(colors[button]);
|
||||
if (color.isValid()) {
|
||||
colors[button] = color;
|
||||
|
||||
drawButtons();
|
||||
drawPreview();
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue