Commit ed30c6c5 authored by Kai Uwe Broulik's avatar Kai Uwe Broulik 🍇
Browse files

[KIconDialog] Revamp UI

This modernizes the UI of KIconDialog that hasn't changed since childhood.
The code is overall tidied up and layout moved into a `.ui` file.

The default size is changed from 4x4 to 6x3 to accommodate more widescreen
monitors and the grid allows for three lines of text since many icon names
are longer than just one line.

Furthermore, the stark separation between "system" and "user" icons is lifted,
and instead the "Browse..." button is always accessible and "Other" is just
another item in the "context" combo box.

Also, a "No icons" placeholder is shown when there are no icons in the
given category or because of the search term input.

Finally, the icons are now loaded on demand as the view scrolls along rather
than loading all thousands of them at once with a slow progress bar.

BUG: 388807
BUG: 401408
parent 4dbe2dfd
......@@ -16,6 +16,10 @@ target_sources(KF5IconThemes PRIVATE
hicolor.qrc
)
# TODO what's that PRIVATE about above?
ki18n_wrap_ui(KF5IconThemes kicondialog.ui)
ecm_qt_declare_logging_category(KF5IconThemes
HEADER debug.h
IDENTIFIER KICONTHEMES
......
This diff is collapsed.
......@@ -5,6 +5,7 @@
SPDX-FileCopyrightText: 2000 Kurt Granroth <granroth@kde.org>
SPDX-FileCopyrightText: 1997 Christoph Neerfeld <chris@kde.org>
SPDX-FileCopyrightText: 2002 Carsten Pfeiffer <pfeiffer@kde.org>
SPDX-FileCopyrightText: 2021 Kai Uwe Broulik <kde@broulik.de>
SPDX-License-Identifier: LGPL-2.0-only
*/
......@@ -153,15 +154,6 @@ private:
Q_DISABLE_COPY(KIconDialog)
Q_PRIVATE_SLOT(d, void _k_slotContext(int))
Q_PRIVATE_SLOT(d, void _k_slotStartLoading(int))
Q_PRIVATE_SLOT(d, void _k_slotProgress(int))
Q_PRIVATE_SLOT(d, void _k_slotFinished())
Q_PRIVATE_SLOT(d, void _k_slotAcceptIcons())
Q_PRIVATE_SLOT(d, void _k_slotBrowse())
Q_PRIVATE_SLOT(d, void _k_customFileSelected(const QString &path))
Q_PRIVATE_SLOT(d, void _k_slotOtherIconClicked())
Q_PRIVATE_SLOT(d, void _k_slotSystemIconClicked())
};
#endif // KICONDIALOG_H
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>IconDialog</class>
<widget class="QWidget" name="IconDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Select Icon</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QComboBox" name="contextCombo">
<property name="accessibleName">
<string>Icon category</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLineEdit" name="searchLine">
<property name="placeholderText">
<string>Search Icons...</string>
</property>
<property name="clearButtonEnabled">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
<item>
<widget class="QListView" name="canvas">
<property name="iconSize">
<size>
<width>60</width>
<height>60</height>
</size>
</property>
<property name="movement">
<enum>QListView::Static</enum>
</property>
<property name="resizeMode">
<enum>QListView::Adjust</enum>
</property>
<property name="viewMode">
<enum>QListView::IconMode</enum>
</property>
<property name="uniformItemSizes">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
......@@ -5,6 +5,7 @@
SPDX-FileCopyrightText: 2000 Kurt Granroth <granroth@kde.org>
SPDX-FileCopyrightText: 1997 Christoph Neerfeld <chris@kde.org>
SPDX-FileCopyrightText: 2002 Carsten Pfeiffer <pfeiffer@kde.org>
SPDX-FileCopyrightText: 2021 Kai Uwe Broulik <kde@broulik.de>
SPDX-License-Identifier: LGPL-2.0-only
*/
......@@ -13,143 +14,60 @@
#define KICONDIALOG_P_H
#include <QFileDialog>
#include <QListWidget>
#include <QPointer>
#include <QPushButton>
#include <QStringList>
#include <QSortFilterProxyModel>
class QComboBox;
class QProgressBar;
class QRadioButton;
#include "kicondialogmodel_p.h"
class KIconCanvasDelegate;
class KListWidgetSearchLine;
#include "ui_kicondialog.h"
/**
* Icon canvas for KIconDialog.
*/
class KIconCanvas : public QListWidget
{
Q_OBJECT
class QLabel;
class QPushButton;
public:
/**
* Creates a new icon canvas.
*
* @param parent The parent widget.
*/
explicit KIconCanvas(QWidget *parent = nullptr);
/**
* Destroys the icon canvas.
*/
~KIconCanvas();
/**
* Load icons into the canvas.
*/
void loadFiles(const QStringList &files);
/**
* Returns the current icon.
*/
QString getCurrent() const;
public Q_SLOTS:
/**
* Call this slot to stop the loading of the icons.
*/
void stopLoading();
Q_SIGNALS:
/**
* Emitted when the current icon has changed.
*/
void nameChanged(const QString &);
/**
* This signal is emitted when the loading of the icons
* has started.
*
* @param count The number of icons to be loaded.
*/
void startLoading(int count);
/**
* This signal is emitted whenever an icon has been loaded.
*
* @param number The number of the currently loaded item.
*/
void progress(int number);
/**
* This signal is emitted when the loading of the icons
* has been finished.
*/
void finished();
private Q_SLOTS:
void loadFiles();
void currentListItemChanged(QListWidgetItem *item);
private:
bool m_loading;
QStringList m_files;
QTimer *m_timer;
KIconCanvasDelegate *m_delegate;
};
class KIconDialog;
class KIconDialogPrivate
{
public:
KIconDialogPrivate(KIconDialog *qq)
: q(qq)
, model(new KIconDialogModel(qq))
, proxyModel(new QSortFilterProxyModel(qq))
{
q = qq;
m_bStrictIconSize = true;
m_bLockUser = false;
m_bLockCustomDir = false;
searchLine = nullptr;
mNumOfSteps = 1;
}
~KIconDialogPrivate()
{
proxyModel->setSourceModel(model);
proxyModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
}
void init();
void showIcons();
void setContext(KIconLoader::Context context);
void updatePlaceholderLabel();
// slots
void _k_slotContext(int);
void _k_slotStartLoading(int);
void _k_slotProgress(int);
void _k_slotFinished();
void _k_slotAcceptIcons();
void _k_slotBrowse();
void _k_customFileSelected(const QString &path);
void _k_slotOtherIconClicked();
void _k_slotSystemIconClicked();
void browse();
bool isSystemIconsContext() const;
KIconDialog *q;
KIconDialogModel *model;
QSortFilterProxyModel *proxyModel;
int mGroupOrSize;
KIconLoader::Context mContext;
QComboBox *mpCombo;
QPushButton *mpBrowseBut;
QRadioButton *mpSystemIcons, *mpOtherIcons;
QProgressBar *mpProgress;
int mNumOfSteps;
QLabel *placeholderLabel;
QPushButton *browseButton;
KIconLoader *mpLoader;
KIconCanvas *mpCanvas;
int mNumContext;
KIconLoader::Context mContextMap[10]; // must match KDE::icon::Context size, code has assert
bool m_bStrictIconSize, m_bLockUser, m_bLockCustomDir;
bool m_bStrictIconSize = true;
bool m_bLockUser = false;
bool m_bLockCustomDir = false;
QString custom;
QString customLocation;
KListWidgetSearchLine *searchLine;
QPointer<QFileDialog> browseDialog;
Ui::IconDialog ui;
};
#endif // KICONDIALOG_P_H
/*
SPDX-FileCopyrightText: 2021 Kai Uwe Broulik <kde@broulik.de>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#ifndef KICONDIALOGMODEL_P_H
#define KICONDIALOGMODEL_P_H
#include <QAbstractListModel>
#include <QPixmap>
#include <QSize>
#include <QString>
#include <QVector>
class QStringList;
struct KIconDialogModelData {
QString name;
QString path;
QPixmap pixmap;
};
Q_DECLARE_TYPEINFO(KIconDialogModelData, Q_MOVABLE_TYPE);
class KIconDialogModel : public QAbstractListModel
{
Q_OBJECT
public:
KIconDialogModel(QObject *parent);
~KIconDialogModel() override;
enum Roles { PathRole = Qt::UserRole };
qreal devicePixelRatio() const;
void setDevicePixelRatio(qreal dpr);
QSize iconSize() const;
void setIconSize(const QSize &iconSize);
void load(const QStringList &paths);
int rowCount(const QModelIndex &parent) const override;
QVariant data(const QModelIndex &index, int role) const override;
private:
void loadPixmap(const QModelIndex &index);
QVector<KIconDialogModelData> m_data;
qreal m_dpr = 1;
QSize m_iconSize;
};
#endif // KICONDIALOGMODEL_P_H
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