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 3914f15e..9e0a9f2f 100644
- --- a/src/options/opt_theme.cpp
- +++ b/src/options/opt_theme.cpp
- @@ -6,12 +6,11 @@
- #include "psithememanager.h"
- #include "psiiconset.h"
- -#include <QToolButton>
- -#include <QDialog>
- #include <QSortFilterProxyModel>
- #include <QTimer>
- +#include <QBuffer>
- -#define SCREEN_PREFIX "scb_"
- +#define LABEL_PREFIX "tl_"
- class OptAppearanceThemeUI : public QWidget, public Ui::OptAppearanceTheme
- {
- @@ -91,6 +90,7 @@ void OptionsTabAppearanceTheme::startLoading()
- void OptionsTabAppearanceTheme::themeSelected(const QModelIndex ¤t, const QModelIndex &previous)
- {
- + Q_UNUSED(current)
- if (!previous.isValid()) {
- return; // Psi won't start if it's impossible to load any theme. So we always have previous.
- }
- @@ -101,7 +101,6 @@ void OptionsTabAppearanceTheme::modelRowsInserted(const QModelIndex &parent, int
- {
- if (!parent.isValid() || !w) {
- OptAppearanceThemeUI *d = (OptAppearanceThemeUI *)w;
- - const QSize buttonSize = QSize(21,21);
- for (int i = first; i <= last; i++) {
- const QModelIndex index = themesModel->index(i, 0);
- const QString id = themesModel->data(index, PsiThemeModel::IdRole).toString();
- @@ -110,79 +109,44 @@ void OptionsTabAppearanceTheme::modelRowsInserted(const QModelIndex &parent, int
- }
- const QString themeName = themesModel->data(index, PsiThemeModel::TitleRole).toString();
- bool isPsi = id.startsWith("psi");
- - const QPixmap client = isPsi ? IconsetFactory::iconPixmap("clients/psi")
- - : IconsetFactory::iconPixmap("clients/adium");
- + 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);
- -
- - QLabel *nameLabel = new QLabel(themeName, d->themeView);
- -
- - QWidget *itemWidget = new QWidget(d->themeView);
- -
- - QBoxLayout *box = new QBoxLayout(QBoxLayout::LeftToRight, d->themeView);
- - box->addWidget(typeLabel);
- - box->addWidget(nameLabel);
- - box->addStretch();
- - box->addWidget(screenshotButton);
- - itemWidget->setLayout(box);
- - //itemWidget->setAutoFillBackground(true); // from recommendation of indexWidget but does not work as expected
- -
- - d->themeView->setIndexWidget(index, itemWidget);
- + typeLabel->setObjectName(LABEL_PREFIX + id);
- + QString itemContents(themeName);
- + if (!client.isNull()) {
- + itemContents =QString("<table width='100%' border='0'><tr>"
- + "<td align='center' width='22'><img src='data:image/png;base64, %0'>"
- + "</td><td align='left'>%1</td>"
- + "</tr></table>").arg(getPixmapBytes(client)).arg(themeName);
- + }
- + typeLabel->setText(itemContents);
- + QString html(clientName);
- + QPixmap scr = unsortedModel->data(index, PsiThemeModel::ScreenshotRole).value<QPixmap>();
- + if (!scr.isNull()) {
- + const QString desc = tr("Screenshot of %1 theme").arg(themeName);
- + html = QString("<table border='0'><tr><td align='center'>"
- + "<b>%0</b>"
- + "</td></tr><tr><td><img src='data:image/png;base64, %1'></td>"
- + "</tr></table>").arg(desc).arg(getPixmapBytes(scr));
- + }
- + typeLabel->setToolTip(html);
- + d->themeView->setIndexWidget(index, typeLabel);
- }
- themesModel->sort(0);
- }
- }
- -void OptionsTabAppearanceTheme::showThemeScreenshot()
- +QString OptionsTabAppearanceTheme::getPixmapBytes(const QPixmap &image) const
- {
- - 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 = unsortedModel->themeRow(getThemeId(btn->objectName()));
- - const QModelIndex index = unsortedModel->index(row, 0);
- - const QString name_ = unsortedModel->data(index, PsiThemeModel::TitleRole).toString();
- - const QPixmap scr = unsortedModel->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);
- + QByteArray imageData;
- + QBuffer imageBuffer(&imageData);
- + imageBuffer.open(QIODevice::WriteOnly);
- + image.save(&imageBuffer, "PNG");
- + return QString(imageData.toBase64());
- - screenshotDialog->setAttribute(Qt::WA_DeleteOnClose);
- - screenshotDialog->show();
- - }
- -}
- -
- -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()
- diff --git a/src/options/opt_theme.h b/src/options/opt_theme.h
- index 44ad6a81..b39d81c5 100644
- --- a/src/options/opt_theme.h
- +++ b/src/options/opt_theme.h
- @@ -2,14 +2,13 @@
- #define OPT_THEME_H
- #include "optionstab.h"
- -#include <QPointer>
- +#include <QPixmap>
- class QModelIndex;
- class QSortFilterProxyModel;
- class QWidget;
- class PsiThemeModel;
- class PsiThemeProvider;
- -class QDialog;
- class OptionsTabAppearanceThemes : public MetaOptionsTab
- {
- @@ -32,20 +31,18 @@ public:
- protected slots:
- void modelRowsInserted(const QModelIndex &parent, int first, int last);
- - void showThemeScreenshot();
- private slots:
- void themeSelected(const QModelIndex ¤t, const QModelIndex &previous);
- void startLoading();
- private:
- - QString getThemeId(const QString &objName) const;
- + QString getPixmapBytes(const QPixmap &image) const;
- private:
- QWidget *w = nullptr;
- PsiThemeModel *unsortedModel = nullptr;
- QSortFilterProxyModel *themesModel = nullptr;
- PsiThemeProvider *provider = nullptr;
- - QPointer<QDialog> screenshotDialog;
- };
- #endif
- diff --git a/src/psithememodel.cpp b/src/psithememodel.cpp
- index 48cc46d0..f1c95e11 100644
- --- a/src/psithememodel.cpp
- +++ b/src/psithememodel.cpp
- @@ -25,6 +25,7 @@
- #include "psithememanager.h"
- +static const QSize minItemSize(100, 32);
- class PsiThemeModel;
- struct PsiThemeModel::Loader
- @@ -152,6 +153,8 @@ QVariant PsiThemeModel::data ( const QModelIndex & index, int role ) const
- }
- case IsCurrent:
- return themesInfo[index.row()].isCurrent;
- + case Qt::SizeHintRole:
- + return minItemSize;
- }
- return QVariant();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement