Commit bd533e95 authored by Alexander Semke's avatar Alexander Semke
Browse files

In the preview widget for themes in the settings dialog allow to show

multiple theme icons in a row to better use the available space. Limit
to one column in the preview for the theme widgets shown in context
menus only.
parent 8f99e4b7
......@@ -673,6 +673,7 @@ void CartesianPlot::initMenus() {
themeMenu = new QMenu(i18n("Apply Theme"));
themeMenu->setIcon(QIcon::fromTheme("color-management"));
auto* themeWidget = new ThemesWidget(nullptr);
themeWidget->setFixedMode();
connect(themeWidget, &ThemesWidget::themeSelected, this, &CartesianPlot::loadTheme);
connect(themeWidget, &ThemesWidget::themeSelected, themeMenu, &QMenu::close);
......
......@@ -567,6 +567,7 @@ void WorksheetView::initMenus() {
m_themeMenu = new QMenu(i18n("Apply Theme"), this);
m_themeMenu->setIcon(QIcon::fromTheme("color-management"));
auto* themeWidget = new ThemesWidget(nullptr);
themeWidget->setFixedMode();
connect(themeWidget, &ThemesWidget::themeSelected, m_worksheet, &Worksheet::setTheme);
connect(themeWidget, &ThemesWidget::themeSelected, m_themeMenu, &QMenu::close);
......
......@@ -186,6 +186,7 @@ void ThemeHandler::loadSelected(const QString& name) {
void ThemeHandler::showPanel() {
QMenu menu;
ThemesWidget themeWidget(&menu);
themeWidget.setFixedMode();
connect(&themeWidget, &ThemesWidget::themeSelected, this, &ThemeHandler::loadSelected);
connect(&themeWidget, &ThemesWidget::themeSelected, &menu, &QMenu::close);
connect(&themeWidget, &ThemesWidget::canceled, &menu, &QMenu::close);
......
......@@ -41,6 +41,8 @@
#include <KMessageBox>
// #include <knewstuff3/downloaddialog.h>
/*!
\class ThemesWidget
\brief Widget for showing theme previews and for selecting a theme.
......@@ -51,12 +53,12 @@ ThemesWidget::ThemesWidget(QWidget* parent) : QListView(parent) {
setSelectionMode(QAbstractItemView::SingleSelection);
setWordWrap(true);
setViewMode(QListWidget::IconMode);
setResizeMode(QListWidget::Fixed);
setResizeMode(QListWidget::Adjust);
setDragDropMode(QListView::NoDragDrop);
//make the icon 3x3cm big and show two of them in the height
int size = 3.0/2.54 * QApplication::desktop()->physicalDpiX();
setIconSize(QSize(size, size));
static const int themeIconSize = 3.0/2.54 * QApplication::desktop()->physicalDpiX();
setIconSize(QSize(themeIconSize, themeIconSize));
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
//show preview pixmaps
......@@ -98,14 +100,6 @@ ThemesWidget::ThemesWidget(QWidget* parent) : QListView(parent) {
QListView::setModel(mContentItemModel);
//resize the widget to show three items
QFont font;
QFontMetrics fm(font);
QSize widgetSize(size + qApp->style()->pixelMetric(QStyle::PM_ScrollBarExtent),
3*(size + fm.height() + spacing()) + fm.height());
setMinimumSize(widgetSize);
setMaximumSize(widgetSize);
//SLOTS
connect(this, &ThemesWidget::clicked, this, &ThemesWidget::applyClicked);
}
......@@ -132,3 +126,14 @@ void ThemesWidget::applyClicked(const QModelIndex& index) {
// kDebug() << "Changed Entry: " << e.name();
// }
// }
void ThemesWidget::setFixedMode() {
//resize the widget to show three items only
QFont font;
QFontMetrics fm(font);
static const int themeIconSize = 3.0/2.54 * QApplication::desktop()->physicalDpiX();
QSize widgetSize(themeIconSize + qApp->style()->pixelMetric(QStyle::PM_ScrollBarExtent),
3*(themeIconSize + fm.height() + 2*spacing()) + fm.height() + spacing());
setMinimumSize(widgetSize);
setMaximumSize(widgetSize);
}
......@@ -36,6 +36,7 @@ class ThemesWidget : public QListView {
public:
explicit ThemesWidget(QWidget*);
void setFixedMode();
signals:
void themeSelected(const QString&);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment