Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/src/options/opt_theme.cpp b/src/options/opt_theme.cpp
- index 173b4473..f8b094a6 100644
- --- a/src/options/opt_theme.cpp
- +++ b/src/options/opt_theme.cpp
- @@ -5,6 +5,14 @@
- #include "psithememodel.h"
- #include "psithemeviewdelegate.h"
- #include "psithememanager.h"
- +#include "psiiconset.h"
- +
- +#include <QRadioButton>
- +#include <QToolButton>
- +#include <QDialog>
- +
- +#define RADIO_PREFIX "rb_"
- +#define SCREEN_PREFIX "scb_"
- class OptAppearanceThemeUI : public QWidget, public Ui::OptAppearanceTheme
- {
- @@ -32,7 +40,7 @@ OptionsTabAppearanceThemes::OptionsTabAppearanceThemes(QObject *parent)
- //----------------------------------------------------------------------------
- OptionsTabAppearanceTheme::OptionsTabAppearanceTheme(QObject *parent,
- - PsiThemeProvider *provider_)
- + PsiThemeProvider *provider_)
- : OptionsTab(parent, provider_->type(), "",
- provider_->optionsName(),
- provider_->optionsDescription())
- @@ -44,7 +52,8 @@ OptionsTabAppearanceTheme::OptionsTabAppearanceTheme(QObject *parent,
- OptionsTabAppearanceTheme::~OptionsTabAppearanceTheme()
- {
- -
- + if(screenshotDialog)
- + delete screenshotDialog;
- }
- QWidget *OptionsTabAppearanceTheme::widget()
- @@ -56,20 +65,16 @@ QWidget *OptionsTabAppearanceTheme::widget()
- OptAppearanceThemeUI *d = (OptAppearanceThemeUI *)w;
- themesModel = new PsiThemeModel(this);
- themesModel->setType(provider->type());
- - PsiThemeViewDelegate *vd = new PsiThemeViewDelegate(d->themeView);
- - d->themeView->setItemDelegate(vd);
- d->themeView->setModel(themesModel);
- - int sw = provider->screenshotWidth();
- - if (sw) {
- - d->themeView->setFixedWidth(sw);
- - }
- connect(d->themeView->selectionModel(),
- - SIGNAL(currentChanged(QModelIndex, QModelIndex)),
- - SIGNAL(dataChanged()));
- -
- + SIGNAL(currentChanged(QModelIndex, QModelIndex)),
- + SIGNAL(dataChanged()));
- + connect(d->themeView->selectionModel(),
- + SIGNAL(currentChanged(QModelIndex,QModelIndex)),
- + SLOT(itemChanged(QModelIndex,QModelIndex))); //changes radiobuttons state
- connect(themesModel,
- - SIGNAL(rowsInserted(QModelIndex,int,int)),
- - SLOT(modelRowsInserted(QModelIndex,int,int)));
- + SIGNAL(rowsInserted(QModelIndex,int,int)),
- + SLOT(modelRowsInserted(QModelIndex,int,int)));
- return w;
- }
- @@ -79,25 +84,154 @@ void OptionsTabAppearanceTheme::modelRowsInserted(const QModelIndex &parent, int
- if (!parent.isValid() || !w) {
- Theme *theme = provider->current();
- OptAppearanceThemeUI *d = (OptAppearanceThemeUI *)w;
- + const QSize buttonSize = QSize(21,21);
- if (theme) {
- for (int i = first; i <= last; i++) {
- - QString id = themesModel->data(themesModel->index(i), PsiThemeModel::IdRole).toString();
- + const QModelIndex index = themesModel->index(i);
- + const QString id = themesModel->data(index, PsiThemeModel::IdRole).toString();
- if (id == theme->id()) {
- - d->themeView->setCurrentIndex(themesModel->index(i));
- - break;
- + d->themeView->setCurrentIndex(index);
- }
- + const QString themeName = themesModel->data(index, PsiThemeModel::TitleRole).toString();
- + bool enabled = (id == provider->current()->id());
- + bool isPsi = id.startsWith("psi");
- + const QPixmap client = isPsi ? IconsetFactory::iconPixmap("clients/psi")
- + : IconsetFactory::iconPixmap("clients/adium");
- + const QString clientName = isPsi ? tr("Psi Theme") : tr("Adium Theme");
- + QToolButton *screenshotButton = new QToolButton(d->themeView);
- + screenshotButton->setIcon(QIcon(IconsetFactory::iconPixmap("psi/eye")));
- + screenshotButton->resize(buttonSize);
- + screenshotButton->setObjectName(SCREEN_PREFIX + id);
- + screenshotButton->setToolTip(tr("Show theme screenshot"));
- + connect(screenshotButton, SIGNAL(clicked()), this, SLOT(showThemeScreenshot()));
- +
- + QLabel *typeLabel = new QLabel(d->themeView);
- + typeLabel->setPixmap(client);
- + typeLabel->setToolTip(clientName);
- +
- + QRadioButton *status = new QRadioButton(d->themeView);
- + status->setObjectName(RADIO_PREFIX + id);
- + status->setChecked(enabled);
- + status->setAutoExclusive(false);
- + status->setText(themeName);
- + connect(status, SIGNAL(toggled(bool)), this, SLOT(radioToggled(bool)));
- +
- + QWidget *itemWidget = new QWidget(d->themeView);
- +
- + QBoxLayout *box = new QBoxLayout(QBoxLayout::LeftToRight, d->themeView);
- + box->addWidget(status);
- + box->addStretch();
- + box->addWidget(typeLabel);
- + box->addWidget(screenshotButton);
- + itemWidget->setLayout(box);
- +
- + d->themeView->setIndexWidget(index, itemWidget);
- + }
- + d->themeView->sortByColumn(0);
- + }
- + }
- +}
- +
- +void OptionsTabAppearanceTheme::showThemeScreenshot()
- +{
- + if ( !w || !sender()->inherits("QToolButton") )
- + return;
- + OptAppearanceThemeUI *d = (OptAppearanceThemeUI *)w;
- + QToolButton *btn = static_cast<QToolButton*>(sender());
- + if ( btn ) {
- + if ( screenshotDialog )
- + delete(screenshotDialog);
- +
- + const QSize minSize(300, 100);
- + screenshotDialog = new QDialog(d);
- + screenshotDialog->setMinimumSize(minSize);
- +
- + const int row = themesModel->themeRow(getThemeId(btn->objectName()));
- + const QModelIndex index = themesModel->index(row);
- + const QString name_ = themesModel->data(index, PsiThemeModel::TitleRole).toString();
- + const QPixmap scr = themesModel->data(index, PsiThemeModel::ScreenshotRole).value<QPixmap>();
- +
- + screenshotDialog->setWindowTitle(tr("%1 Screenshot").arg(name_));
- + screenshotDialog->setWindowIcon(QIcon(IconsetFactory::iconPixmap("psi/logo_128")));
- +
- + QBoxLayout *box = new QBoxLayout(QBoxLayout::LeftToRight, screenshotDialog);
- + QLabel *image = new QLabel(screenshotDialog);
- + if (!scr.isNull()) {
- + image->setPixmap(scr);
- + }
- + else {
- + image->setText(tr("No Image"));
- + }
- + box->addWidget(image);
- +
- + screenshotDialog->setAttribute(Qt::WA_DeleteOnClose);
- + screenshotDialog->show();
- + }
- +}
- +
- +void OptionsTabAppearanceTheme::radioToggled(bool toggled)
- +{
- + if ( !w || !sender()->inherits("QRadioButton"))
- + return;
- +
- + OptAppearanceThemeUI *d = (OptAppearanceThemeUI *)w;
- + QRadioButton *btn = static_cast<QRadioButton*>(sender());
- + const QString btnObjectName = btn->objectName();
- + if (btn && toggled) {
- + const QModelIndex index = themesModel->index(themesModel->themeRow(getThemeId(btnObjectName)));
- + if (index != d->themeView->currentIndex()) {
- + d->themeView->setCurrentIndex(index);
- + }
- + }
- + uncheckAll(btnObjectName);
- +}
- +
- +void OptionsTabAppearanceTheme::uncheckAll(const QString &name_)
- +{
- + if ( !w )
- + return;
- +
- + OptAppearanceThemeUI *d = (OptAppearanceThemeUI *)w;
- + const QList<QRadioButton*> buttons = d->themeView->findChildren<QRadioButton*>(QRegExp(RADIO_PREFIX"*"));
- + if (!buttons.isEmpty()) {
- + foreach (QRadioButton *b, buttons) {
- + if (b->objectName() != name_) {
- + b->setChecked(false);
- }
- }
- }
- }
- +void OptionsTabAppearanceTheme::itemChanged(const QModelIndex ¤t, const QModelIndex &previous)
- +{
- + if ( !w )
- + return;
- +
- + Q_UNUSED(previous)
- + OptAppearanceThemeUI *d = (OptAppearanceThemeUI *)w;
- + const QString id = themesModel->data(current, PsiThemeModel::IdRole).toString();
- + if (!id.isEmpty()) {
- + QRadioButton *btn = d->themeView->findChild<QRadioButton*>(QString("%1%2").arg(RADIO_PREFIX).arg(id));
- + if (btn) {
- + uncheckAll(btn->objectName());
- + btn->setChecked(!btn->isChecked());
- + }
- + }
- +}
- +
- +QString OptionsTabAppearanceTheme::getThemeId(const QString &objName) const
- +{
- + const int index = objName.indexOf("_", 0);
- + return (index >0 ? objName.right(objName.length() - index - 1) : QString());
- +}
- +
- void OptionsTabAppearanceTheme::applyOptions()
- {
- if ( !w )
- return;
- OptAppearanceThemeUI *d = (OptAppearanceThemeUI *)w;
- - QString id = d->themeView->currentIndex().data(PsiThemeModel::IdRole).toString();
- + const QString id = d->themeView->currentIndex().data(PsiThemeModel::IdRole).toString();
- if (!id.isEmpty()) {
- provider->setCurrentTheme(id);
- }
- diff --git a/src/options/opt_theme.h b/src/options/opt_theme.h
- index b9916110..c3a248ca 100644
- --- a/src/options/opt_theme.h
- +++ b/src/options/opt_theme.h
- @@ -2,11 +2,13 @@
- #define OPT_THEME_H
- #include "optionstab.h"
- +#include <QPointer>
- class QModelIndex;
- class QWidget;
- class PsiThemeModel;
- class PsiThemeProvider;
- +class QDialog;
- class OptionsTabAppearanceThemes : public MetaOptionsTab
- {
- @@ -29,11 +31,19 @@ public:
- protected slots:
- void modelRowsInserted(const QModelIndex &parent, int first, int last);
- + void itemChanged(const QModelIndex ¤t, const QModelIndex &previous);
- + void showThemeScreenshot();
- + void radioToggled(bool toggled);
- +
- +private:
- + QString getThemeId(const QString &objName) const;
- + void uncheckAll(const QString &name_);
- private:
- QWidget *w;
- PsiThemeModel *themesModel;
- PsiThemeProvider *provider;
- + QPointer<QDialog> screenshotDialog;
- };
- #endif
- diff --git a/src/options/opt_theme.ui b/src/options/opt_theme.ui
- index e526e20d..75f3750c 100644
- --- a/src/options/opt_theme.ui
- +++ b/src/options/opt_theme.ui
- @@ -17,20 +17,26 @@
- <item>
- <layout class="QHBoxLayout" name="adapterLayout">
- <item>
- - <widget class="QListView" name="themeView"/>
- - </item>
- - <item>
- - <spacer name="horizontalSpacer_2">
- - <property name="orientation">
- - <enum>Qt::Horizontal</enum>
- + <widget class="QTreeView" name="themeView">
- + <property name="editTriggers">
- + <set>QAbstractItemView::NoEditTriggers</set>
- </property>
- - <property name="sizeHint" stdset="0">
- - <size>
- - <width>40</width>
- - <height>20</height>
- - </size>
- + <property name="showDropIndicator" stdset="0">
- + <bool>false</bool>
- </property>
- - </spacer>
- + <property name="rootIsDecorated">
- + <bool>false</bool>
- + </property>
- + <property name="sortingEnabled">
- + <bool>true</bool>
- + </property>
- + <property name="headerHidden">
- + <bool>true</bool>
- + </property>
- + <property name="expandsOnDoubleClick">
- + <bool>false</bool>
- + </property>
- + </widget>
- </item>
- </layout>
- </item>
- diff --git a/src/psithememodel.cpp b/src/psithememodel.cpp
- index 9720b43a..4f7ec3b2 100644
- --- a/src/psithememodel.cpp
- +++ b/src/psithememodel.cpp
- @@ -114,8 +114,7 @@ void PsiThemeModel::setType(const QString &type)
- themesFuture = QtConcurrent::mapped(provider->themeIds(), loader);
- themeWatcher.setFuture(themesFuture);
- } else {
- -
- - foreach (const QString id, provider->themeIds()) {
- + foreach (const QString &id, provider->themeIds()) {
- loader.asyncLoad(id, [this](const ThemeItemInfo &ti) {
- if (ti.isValid) {
- beginInsertRows(QModelIndex(), themesInfo.size(), themesInfo.size());
- @@ -125,6 +124,7 @@ void PsiThemeModel::setType(const QString &type)
- //endResetModel();
- }
- });
- +
- }
- }
- }
- diff --git a/src/psithemeviewdelegate.cpp b/src/psithemeviewdelegate.cpp
- deleted file mode 100644
- index 81e4e9e5..00000000
- --- a/src/psithemeviewdelegate.cpp
- +++ /dev/null
- @@ -1,86 +0,0 @@
- -/*
- - * psithemeviewdelegate.cpp - renders theme items
- - * Copyright (C) 2010 Rion (Sergey Ilinyh)
- - *
- - * 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 library; if not, write to the Free Software
- - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- - *
- - */
- -
- -#include "psithemeviewdelegate.h"
- -#include "psithememodel.h"
- -#include <QPainter>
- -#include <QFontMetrics>
- -#include "iconset.h"
- -
- -// painting
- -void PsiThemeViewDelegate::paint(QPainter *painter,
- - const QStyleOptionViewItem &option,
- - const QModelIndex &index) const
- -{
- - QPixmap screenshot = index.data(PsiThemeModel::ScreenshotRole).value<QPixmap>();
- - QPixmap texture = IconsetFactory::iconPixmap("psi/themeTitleTexture");
- - int texturew = texture.width();
- - int textureh = texture.height();
- -
- - QFont f("Serif");
- - f.setBold(true);
- - if (screenshot.isNull()) {
- - f.setPixelSize(20);
- - painter->setFont(f);
- - painter->setPen(QColor(170, 170, 170));
- - QRect nirect(0, option.rect.top() + textureh, option.rect.width(), 20);
- - painter->drawText(nirect, Qt::AlignCenter, tr("No Image"));
- - } else {
- - QRect sp = screenshot.rect();
- - sp.moveTopLeft(option.rect.topLeft());
- - painter->drawPixmap(sp, screenshot);
- - }
- -
- - f.setItalic(true);
- - f.setPixelSize(textureh - 8);
- - painter->setFont(f);
- - QFontMetrics fm(f);
- - QString text = index.data(PsiThemeModel::TitleRole).toString();
- - QSize textSize = fm.size(Qt::TextSingleLine, text);
- - int tw = textSize.width() + 10;
- - int y = option.rect.top();
- - int vw = option.rect.width();
- -
- - painter->drawPixmap(0, y, vw - tw - texturew, textureh, texture.copy(0, 0, 1, textureh).scaled(vw - tw - texturew, textureh));
- - painter->drawPixmap(vw - tw - texturew, y, texturew, textureh, texture);
- - painter->drawPixmap(vw - tw, y, tw, textureh, texture.copy(texturew - 1, 0, 1, textureh).scaled(tw, textureh));
- -
- -
- - painter->setPen(option.state & QStyle::State_Selected? Qt::white : QColor(170, 170, 170));
- - QRect txtr(vw - tw, y, tw, textureh-5); // 5 shadow size?
- - painter->drawText(txtr, Qt::AlignCenter, text);
- -}
- -
- -QSize PsiThemeViewDelegate::sizeHint(const QStyleOptionViewItem &option,
- - const QModelIndex &index) const
- -{
- - int textureh = IconsetFactory::iconPixmap("psi/themeTitleTexture").height();
- - QPixmap screenshot = index.data(PsiThemeModel::ScreenshotRole).value<QPixmap>();
- - int h = screenshot.isNull()? textureh + 20 : qMax(textureh, screenshot.height());
- - return QSize(option.rect.width(), h);
- -}
- -
- -// editing
- -QWidget *PsiThemeViewDelegate::createEditor(QWidget */*parent*/,
- - const QStyleOptionViewItem &/*option*/,
- - const QModelIndex &/*index*/) const
- -{
- - return 0;
- -}
- diff --git a/src/psithemeviewdelegate.h b/src/psithemeviewdelegate.h
- deleted file mode 100644
- index 8ee8026b..00000000
- --- a/src/psithemeviewdelegate.h
- +++ /dev/null
- @@ -1,49 +0,0 @@
- -/*
- - * psithemeviewdelegate.h - renders theme items
- - * Copyright (C) 2010 Rion (Sergey Ilinyh)
- - *
- - * 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 library; if not, write to the Free Software
- - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- - *
- - */
- -
- -#ifndef PSITHEMEVIEWDELEGATE_H
- -#define PSITHEMEVIEWDELEGATE_H
- -
- -#include <QAbstractItemDelegate>
- -
- -class PsiThemeViewDelegate : public QAbstractItemDelegate
- -{
- - Q_OBJECT
- -public:
- - PsiThemeViewDelegate ( QObject * parent = 0 )
- - : QAbstractItemDelegate ( parent ) { }
- -
- - // painting
- - virtual void paint(QPainter *painter,
- - const QStyleOptionViewItem &option,
- - const QModelIndex &index) const;
- -
- - virtual QSize sizeHint(const QStyleOptionViewItem &option,
- - const QModelIndex &index) const;
- -
- - // editing
- - virtual QWidget *createEditor(QWidget *parent,
- - const QStyleOptionViewItem &option,
- - const QModelIndex &index) const;
- -
- - static const int TextPadding = 3;
- -};
- -
- -#endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement