! \class ThemesWidget \brief Widget for showing theme previews and for selecting a theme. \ingroup frontend */
| 36 | \ingroup frontend |
| 37 | */ |
| 38 | ThemesWidget::ThemesWidget(QWidget* parent) |
| 39 | : QListView(parent) { |
| 40 | setSelectionMode(QAbstractItemView::SingleSelection); |
| 41 | setWordWrap(true); |
| 42 | setViewMode(QListWidget::IconMode); |
| 43 | setResizeMode(QListWidget::Adjust); |
| 44 | setDragDropMode(QListView::NoDragDrop); |
| 45 | |
| 46 | // make the icon 3x3cm big and show two of them in the height |
| 47 | static const int themeIconSize = std::ceil(3.0 / GSL_CONST_CGS_INCH * GuiTools::dpi(this).first); |
| 48 | setIconSize(QSize(themeIconSize, themeIconSize)); |
| 49 | setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
| 50 | |
| 51 | // show preview pixmaps |
| 52 | auto* mContentItemModel = new QStandardItemModel(this); |
| 53 | auto themeList = ThemeHandler::themes(); |
| 54 | auto themeImgPathList = QStandardPaths::locateAll(QStandardPaths::AppDataLocation, QStringLiteral("themes/screenshots/"), QStandardPaths::LocateDirectory); |
| 55 | if (themeImgPathList.isEmpty()) { |
| 56 | delete mContentItemModel; |
| 57 | return; |
| 58 | } |
| 59 | |
| 60 | const QString& themeImgPath = themeImgPathList.first(); |
| 61 | |
| 62 | for (int i = 0; i < themeList.size(); ++i) { |
| 63 | auto* listItem = new QStandardItem(); |
| 64 | |
| 65 | QString tempPath = themeImgPath + themeList.at(i) + QStringLiteral(".png"); |
| 66 | if (!QFile::exists(tempPath)) |
| 67 | tempPath = themeImgPath + QStringLiteral("Unavailable.png"); |
| 68 | |
| 69 | listItem->setIcon(QIcon(QPixmap(tempPath))); |
| 70 | if (themeList.at(i) == QLatin1String("Default")) { |
| 71 | listItem->setText(i18n("Default")); |
| 72 | mContentItemModel->insertRow(0, listItem); |
| 73 | } else { |
| 74 | listItem->setText(themeList.at(i)); |
| 75 | mContentItemModel->appendRow(listItem); |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | // adding download themes option |
| 80 | // TODO: activate this later |
| 81 | // auto* listItem = new QStandardItem(); |
| 82 | // listItem->setIcon(QIcon::fromTheme("get-hot-new-stuff")); |
| 83 | // listItem->setText("Download Themes"); |
| 84 | // listItem->setData("file_download_theme", Qt::UserRole); |
| 85 | // mContentItemModel->appendRow(listItem); |
| 86 | |
| 87 | QListView::setModel(mContentItemModel); |
| 88 | |
| 89 | // SLOTS |
| 90 | connect(this, &ThemesWidget::clicked, this, &ThemesWidget::applyClicked); |
| 91 | } |
| 92 | |
| 93 | void ThemesWidget::applyClicked(const QModelIndex& index) { |
| 94 | const QString& themeName = index.data(Qt::DisplayRole).toString(); |