Apply clang-format

This commit is contained in:
Martchus 2017-05-01 03:16:25 +02:00
parent 61a544d42f
commit 2dcbc02f4b
57 changed files with 891 additions and 978 deletions

3
.gitignore vendored
View File

@ -39,3 +39,6 @@ Makefile*
# documentation
/doc
# clang-format
/.clang-format

View File

@ -3,9 +3,9 @@
#include "ui_aboutdialog.h"
#include <QGraphicsPixmapItem>
#include <QApplication>
#include <QDesktopWidget>
#include <QGraphicsPixmapItem>
#include <QStyle>
/*!
@ -30,47 +30,50 @@ namespace Dialogs {
* \param website Specifies the URL to the website of the application. If empty, QApplication::organizationDomain() will be used.
* \param image Specifies the application icon. If the image is null, the standard information icon will be used.
*/
AboutDialog::AboutDialog(QWidget *parent, const QString &applicationName, const QString &creator, const QString &version, const QString &website, const QString &description, const QImage &image) :
QDialog(parent),
m_ui(new Ui::AboutDialog)
AboutDialog::AboutDialog(QWidget *parent, const QString &applicationName, const QString &creator, const QString &version, const QString &website,
const QString &description, const QImage &image)
: QDialog(parent)
, m_ui(new Ui::AboutDialog)
{
m_ui->setupUi(this);
makeHeading(m_ui->productNameLabel);
setStyleSheet(dialogStyle());
setWindowFlags(Qt::Tool);
if(!applicationName.isEmpty()) {
if (!applicationName.isEmpty()) {
m_ui->productNameLabel->setText(applicationName);
} else if(!QApplication::applicationDisplayName().isEmpty()) {
} else if (!QApplication::applicationDisplayName().isEmpty()) {
m_ui->productNameLabel->setText(QApplication::applicationDisplayName());
} else {
m_ui->productNameLabel->setText(QApplication::applicationName());
}
m_ui->creatorLabel->setText(tr("developed by %1").arg(
creator.isEmpty() ? QApplication::organizationName() : creator));
m_ui->creatorLabel->setText(tr("developed by %1").arg(creator.isEmpty() ? QApplication::organizationName() : creator));
m_ui->versionLabel->setText(version.isEmpty() ? QApplication::applicationVersion() : version);
m_ui->websiteLabel->setText(tr("For updates and bug reports visit the <a href=\"%1\" style=\"text-decoration: underline; color: palette(link);\">project website</a>.").arg(
website.isEmpty() ? QApplication::organizationDomain() : website));
m_ui->websiteLabel->setText(
tr("For updates and bug reports visit the <a href=\"%1\" style=\"text-decoration: underline; color: palette(link);\">project website</a>.")
.arg(website.isEmpty() ? QApplication::organizationDomain() : website));
m_ui->descLabel->setText(description);
m_iconScene = new QGraphicsScene(this);
auto *item = image.isNull()
? new QGraphicsPixmapItem(QApplication::style()->standardIcon(QStyle::SP_MessageBoxInformation, nullptr, this).pixmap(128))
: new QGraphicsPixmapItem(QPixmap::fromImage(image));
? new QGraphicsPixmapItem(QApplication::style()->standardIcon(QStyle::SP_MessageBoxInformation, nullptr, this).pixmap(128))
: new QGraphicsPixmapItem(QPixmap::fromImage(image));
m_iconScene->addItem(item);
m_ui->graphicsView->setScene(m_iconScene);
setGeometry(QStyle::alignedRect(Qt::LeftToRight, Qt::AlignCenter, size(), parentWidget() ? parentWidget()->geometry() : QApplication::desktop()->availableGeometry()));
setGeometry(QStyle::alignedRect(
Qt::LeftToRight, Qt::AlignCenter, size(), parentWidget() ? parentWidget()->geometry() : QApplication::desktop()->availableGeometry()));
}
/*!
* \brief Constructs an about dialog with the specified \a parent, \a description and \a image.
*/
AboutDialog::AboutDialog(QWidget *parent, const QString &description, const QImage &image) :
AboutDialog(parent, QString(), QString(), QString(), QString(), description, image)
{}
AboutDialog::AboutDialog(QWidget *parent, const QString &description, const QImage &image)
: AboutDialog(parent, QString(), QString(), QString(), QString(), description, image)
{
}
/*!
* \brief Destroys the about dialog.
*/
AboutDialog::~AboutDialog()
{}
{
}
}

View File

@ -15,12 +15,12 @@ namespace Ui {
class AboutDialog;
}
class QT_UTILITIES_EXPORT AboutDialog : public QDialog
{
class QT_UTILITIES_EXPORT AboutDialog : public QDialog {
Q_OBJECT
public:
explicit AboutDialog(QWidget *parent, const QString &applicationName, const QString &creator, const QString &version, const QString &website = QString(), const QString &description = QString(), const QImage &image = QImage());
explicit AboutDialog(QWidget *parent, const QString &applicationName, const QString &creator, const QString &version,
const QString &website = QString(), const QString &description = QString(), const QImage &image = QImage());
explicit AboutDialog(QWidget *parent, const QString &description = QString(), const QImage &image = QImage());
~AboutDialog();
@ -28,7 +28,6 @@ private:
std::unique_ptr<Ui::AboutDialog> m_ui;
QGraphicsScene *m_iconScene;
};
}
#endif // DIALOGS_ABOUTDIALOG_H

View File

@ -5,20 +5,20 @@
#include <QEvent>
#include <QGraphicsPixmapItem>
#include <QGuiApplication>
#include <QKeyEvent>
#include <QMessageBox>
#include <QGuiApplication>
#ifdef QT_UTILITIES_PLATFORM_SPECIFIC_CAPSLOCK_DETECTION
# if defined(Q_OS_WIN32)
# include <windows.h>
# elif defined(X_AVAILABLE)
# include <X11/XKBlib.h>
# undef KeyPress
# undef KeyRelease
# undef FocusIn
# undef FocusOut
# endif
#if defined(Q_OS_WIN32)
#include <windows.h>
#elif defined(X_AVAILABLE)
#include <X11/XKBlib.h>
#undef KeyPress
#undef KeyRelease
#undef FocusIn
#undef FocusOut
#endif
#endif
namespace Dialogs {
@ -32,9 +32,9 @@ namespace Dialogs {
* \brief Constructs a password dialog.
* \param parent Specifies the parent widget.
*/
EnterPasswordDialog::EnterPasswordDialog(QWidget *parent) :
QDialog(parent),
m_ui(new Ui::EnterPasswordDialog)
EnterPasswordDialog::EnterPasswordDialog(QWidget *parent)
: QDialog(parent)
, m_ui(new Ui::EnterPasswordDialog)
{
// setup ui
m_ui->setupUi(this);
@ -48,7 +48,7 @@ EnterPasswordDialog::EnterPasswordDialog(QWidget *parent) :
m_ui->userNameLineEdit->installEventFilter(this);
m_ui->password1LineEdit->installEventFilter(this);
m_ui->password2LineEdit->installEventFilter(this);
// capslock key detection
// capslock key detection
#ifdef QT_UTILITIES_PLATFORM_SPECIFIC_CAPSLOCK_DETECTION
m_capslockPressed = isCapslockPressed();
#else
@ -57,14 +57,14 @@ EnterPasswordDialog::EnterPasswordDialog(QWidget *parent) :
m_ui->capslockWarningWidget->setVisible(m_capslockPressed);
// draw icon to capslock warning graphics view
QIcon icon = QApplication::style()->standardIcon(QStyle::SP_MessageBoxWarning, nullptr, this);
QGraphicsScene* scene = new QGraphicsScene();
QGraphicsPixmapItem* item = new QGraphicsPixmapItem(icon.pixmap(16, 16));
QGraphicsScene *scene = new QGraphicsScene();
QGraphicsPixmapItem *item = new QGraphicsPixmapItem(icon.pixmap(16, 16));
scene->addItem(item);
m_ui->capslockWarningGraphicsView->setScene(scene);
// connect signals and slots
connect(m_ui->showPasswordCheckBox, &QCheckBox::clicked, this, &EnterPasswordDialog::updateShowPassword);
connect(m_ui->noPwCheckBox, &QCheckBox::clicked, this, &EnterPasswordDialog::updateShowPassword);
connect(m_ui->confirmPushButton, &QPushButton::clicked, this, &EnterPasswordDialog::confirm);
connect(m_ui->noPwCheckBox, &QCheckBox::clicked, this, &EnterPasswordDialog::updateShowPassword);
connect(m_ui->confirmPushButton, &QPushButton::clicked, this, &EnterPasswordDialog::confirm);
connect(m_ui->abortPushButton, &QPushButton::clicked, this, &EnterPasswordDialog::abort);
// grab the keyboard
grabKeyboard();
@ -74,7 +74,8 @@ EnterPasswordDialog::EnterPasswordDialog(QWidget *parent) :
* \brief Destroys the password dialog.
*/
EnterPasswordDialog::~EnterPasswordDialog()
{}
{
}
/*!
* \brief Returns the description. The description is shown under the instruction text.
@ -163,9 +164,7 @@ void EnterPasswordDialog::setPasswordRequired(bool value)
*/
void EnterPasswordDialog::updateShowPassword()
{
m_ui->password1LineEdit->setEchoMode(m_ui->showPasswordCheckBox->isChecked()
? QLineEdit::Normal
: QLineEdit::Password);
m_ui->password1LineEdit->setEchoMode(m_ui->showPasswordCheckBox->isChecked() ? QLineEdit::Normal : QLineEdit::Password);
m_ui->password1LineEdit->setEnabled(!m_ui->noPwCheckBox->isChecked());
m_ui->password2LineEdit->setEnabled(!(m_ui->showPasswordCheckBox->isChecked() || m_ui->noPwCheckBox->isChecked()));
}
@ -177,7 +176,7 @@ void EnterPasswordDialog::updateShowPassword()
*/
void EnterPasswordDialog::setVerificationRequired(bool value)
{
if(m_instruction.isEmpty()) {
if (m_instruction.isEmpty()) {
m_ui->instructionLabel->setText(value ? tr("Enter the new password") : tr("Enter the password"));
}
m_ui->password2LineEdit->setHidden(!value);
@ -192,7 +191,7 @@ void EnterPasswordDialog::setVerificationRequired(bool value)
void EnterPasswordDialog::setInstruction(const QString &value)
{
m_instruction = value;
if(m_instruction.isEmpty()) {
if (m_instruction.isEmpty()) {
m_ui->instructionLabel->setText(isVerificationRequired() ? tr("Enter the new password") : tr("Enter the password"));
} else {
m_ui->instructionLabel->setText(value);
@ -202,17 +201,16 @@ void EnterPasswordDialog::setInstruction(const QString &value)
bool EnterPasswordDialog::event(QEvent *event)
{
switch(event->type()) {
switch (event->type()) {
case QEvent::KeyPress: {
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
if(keyEvent->key() == Qt::Key_CapsLock) {
if (keyEvent->key() == Qt::Key_CapsLock) {
m_capslockPressed = !m_capslockPressed;
}
m_ui->capslockWarningWidget->setVisible(m_capslockPressed);
break;
}
default:
;
default:;
}
return QDialog::event(event);
}
@ -224,40 +222,38 @@ bool EnterPasswordDialog::event(QEvent *event)
*/
bool EnterPasswordDialog::eventFilter(QObject *sender, QEvent *event)
{
switch(event->type()) {
switch (event->type()) {
case QEvent::KeyPress: {
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
if(keyEvent->key() == Qt::Key_CapsLock) {
if (keyEvent->key() == Qt::Key_CapsLock) {
m_capslockPressed = !m_capslockPressed;
} else {
QString text = keyEvent->text();
if(text.length()) {
if (text.length()) {
QChar firstChar = text.at(0);
bool shiftPressed = (keyEvent->modifiers() & Qt::ShiftModifier) != 0;
if((shiftPressed && firstChar.isLower()) || (!shiftPressed && firstChar.isUpper())) {
if ((shiftPressed && firstChar.isLower()) || (!shiftPressed && firstChar.isUpper())) {
m_capslockPressed = true;
} else if(firstChar.isLetter()) {
} else if (firstChar.isLetter()) {
m_capslockPressed = false;
}
}
}
m_ui->capslockWarningWidget->setVisible(m_capslockPressed);
}
break;
} break;
case QEvent::FocusIn:
if(sender == m_ui->userNameLineEdit || sender == m_ui->password1LineEdit || sender == m_ui->password2LineEdit) {
if (sender == m_ui->userNameLineEdit || sender == m_ui->password1LineEdit || sender == m_ui->password2LineEdit) {
releaseKeyboard();
qobject_cast<QWidget *>(sender)->grabKeyboard();
}
break;
case QEvent::FocusOut:
if(sender == m_ui->userNameLineEdit || sender == m_ui->password1LineEdit || sender == m_ui->password2LineEdit) {
if (sender == m_ui->userNameLineEdit || sender == m_ui->password1LineEdit || sender == m_ui->password2LineEdit) {
qobject_cast<QWidget *>(sender)->releaseKeyboard();
grabKeyboard();
}
break;
default:
;
default:;
}
return false;
}
@ -270,20 +266,20 @@ bool EnterPasswordDialog::eventFilter(QObject *sender, QEvent *event)
*/
void EnterPasswordDialog::confirm()
{
if(!isPasswordRequired() && m_ui->noPwCheckBox->isChecked()) {
if (!isPasswordRequired() && m_ui->noPwCheckBox->isChecked()) {
m_password.clear();
done(QDialog::Accepted);
} else {
QString userName = m_ui->userNameLineEdit->text();
QString password = m_ui->password1LineEdit->text();
QString repeatedPassword = m_ui->password2LineEdit->text();
if(promtForUserName() && userName.isEmpty()) {
if (promtForUserName() && userName.isEmpty()) {
QMessageBox::warning(this, windowTitle(), tr("You didn't enter a user name."));
} else if(password.isEmpty()) {
} else if (password.isEmpty()) {
QMessageBox::warning(this, windowTitle(), tr("You didn't enter a password."));
} else {
if(isVerificationRequired() && (password != repeatedPassword) && !m_ui->showPasswordCheckBox->isChecked()) {
if(repeatedPassword.isEmpty()) {
if (isVerificationRequired() && (password != repeatedPassword) && !m_ui->showPasswordCheckBox->isChecked()) {
if (repeatedPassword.isEmpty()) {
QMessageBox::warning(this, windowTitle(), tr("You have to enter the new password twice to ensure you enterd it correct."));
} else {
QMessageBox::warning(this, windowTitle(), tr("You mistyped the password."));
@ -310,11 +306,11 @@ void EnterPasswordDialog::confirm()
bool EnterPasswordDialog::isCapslockPressed()
{
#ifdef QT_UTILITIES_PLATFORM_SPECIFIC_CAPSLOCK_DETECTION
// platform dependent method of determining if CAPS LOCK is pressed
# if defined(Q_OS_WIN32)
// platform dependent method of determining if CAPS LOCK is pressed
#if defined(Q_OS_WIN32)
return GetKeyState(VK_CAPITAL) == 1;
# elif defined(X_AVAILABLE)
Display *d = XOpenDisplay((char*)0);
#elif defined(X_AVAILABLE)
Display *d = XOpenDisplay((char *)0);
bool caps_state = false;
if (d) {
unsigned n;
@ -322,12 +318,11 @@ bool EnterPasswordDialog::isCapslockPressed()
caps_state = (n & 0x01) == 1;
}
return caps_state;
# else
#else
return false;
# endif
#endif
#else
return false;
#endif
}
}

View File

@ -13,8 +13,7 @@ namespace Ui {
class EnterPasswordDialog;
}
class QT_UTILITIES_EXPORT EnterPasswordDialog : public QDialog
{
class QT_UTILITIES_EXPORT EnterPasswordDialog : public QDialog {
Q_OBJECT
Q_PROPERTY(QString userName READ userName)
Q_PROPERTY(QString password READ password)
@ -100,7 +99,6 @@ inline void EnterPasswordDialog::abort()
m_password.clear();
done(QDialog::Rejected);
}
}
#endif // DIALOGS_ENTERPASSWORDDIALOG_H

View File

@ -7,11 +7,11 @@
#include <c++utilities/application/global.h>
#ifdef QT_UTILITIES_STATIC
# define QT_UTILITIES_EXPORT
# define QT_UTILITIES_IMPORT
#define QT_UTILITIES_EXPORT
#define QT_UTILITIES_IMPORT
#else
# define QT_UTILITIES_EXPORT LIB_EXPORT
# define QT_UTILITIES_IMPORT LIB_IMPORT
#define QT_UTILITIES_EXPORT LIB_EXPORT
#define QT_UTILITIES_IMPORT LIB_IMPORT
#endif
/*!

View File

@ -10,16 +10,15 @@ namespace ThreadingUtils {
/*!
* \brief Like QMutexLocker, but assumes that the mutex has already been locked.
*/
template<typename Mutex = QMutex>
class AdoptLocker
{
template <typename Mutex = QMutex> class AdoptLocker {
public:
/*!
* \brief Constructs the locker for the specified \a mutex.
*/
AdoptLocker(Mutex &mutex) :
m_mutex(mutex)
{}
AdoptLocker(Mutex &mutex)
: m_mutex(mutex)
{
}
/*!
* \brief Unlocks the mutex specified when constructing the instance.
@ -32,7 +31,6 @@ public:
private:
Mutex &m_mutex;
};
}
#endif // THEADING_UTILS_ADOPTLOCKER_H

View File

@ -36,12 +36,12 @@ OrgFreedesktopNotificationsInterface *DBusNotification::m_dbusInterface = nullpt
/*!
* \brief Creates a new notification (which is *not* shown instantly).
*/
DBusNotification::DBusNotification(const QString &title, NotificationIcon icon, int timeout, QObject *parent) :
QObject(parent),
m_id(0),
m_watcher(nullptr),
m_title(title),
m_timeout(timeout)
DBusNotification::DBusNotification(const QString &title, NotificationIcon icon, int timeout, QObject *parent)
: QObject(parent)
, m_id(0)
, m_watcher(nullptr)
, m_title(title)
, m_timeout(timeout)
{
initInterface();
setIcon(icon);
@ -50,13 +50,13 @@ DBusNotification::DBusNotification(const QString &title, NotificationIcon icon,
/*!
* \brief Creates a new notification (which is *not* shown instantly).
*/
DBusNotification::DBusNotification(const QString &title, const QString &icon, int timeout, QObject *parent) :
QObject(parent),
m_id(0),
m_watcher(nullptr),
m_title(title),
m_icon(icon),
m_timeout(timeout)
DBusNotification::DBusNotification(const QString &title, const QString &icon, int timeout, QObject *parent)
: QObject(parent)
, m_id(0)
, m_watcher(nullptr)
, m_title(title)
, m_icon(icon)
, m_timeout(timeout)
{
initInterface();
}
@ -66,8 +66,9 @@ DBusNotification::DBusNotification(const QString &title, const QString &icon, in
*/
void DBusNotification::initInterface()
{
if(!m_dbusInterface) {
m_dbusInterface = new OrgFreedesktopNotificationsInterface(QStringLiteral("org.freedesktop.Notifications"), QStringLiteral("/org/freedesktop/Notifications"), QDBusConnection::sessionBus());
if (!m_dbusInterface) {
m_dbusInterface = new OrgFreedesktopNotificationsInterface(
QStringLiteral("org.freedesktop.Notifications"), QStringLiteral("/org/freedesktop/Notifications"), QDBusConnection::sessionBus());
connect(m_dbusInterface, &OrgFreedesktopNotificationsInterface::ActionInvoked, &DBusNotification::handleActionInvoked);
connect(m_dbusInterface, &OrgFreedesktopNotificationsInterface::NotificationClosed, &DBusNotification::handleNotificationClosed);
}
@ -79,7 +80,7 @@ void DBusNotification::initInterface()
DBusNotification::~DBusNotification()
{
auto i = pendingNotifications.find(m_id);
if(i != pendingNotifications.end()) {
if (i != pendingNotifications.end()) {
pendingNotifications.erase(i);
}
hide();
@ -99,15 +100,17 @@ bool DBusNotification::isAvailable()
*/
void DBusNotification::setIcon(NotificationIcon icon)
{
switch(icon) {
switch (icon) {
case NotificationIcon::Information:
m_icon = QStringLiteral("dialog-information"); break;
m_icon = QStringLiteral("dialog-information");
break;
case NotificationIcon::Warning:
m_icon = QStringLiteral("dialog-warning"); break;
m_icon = QStringLiteral("dialog-warning");
break;
case NotificationIcon::Critical:
m_icon = QStringLiteral("dialog-critical"); break;
default:
;
m_icon = QStringLiteral("dialog-critical");
break;
default:;
}
}
@ -127,13 +130,14 @@ void DBusNotification::deleteOnCloseOrError()
*/
bool DBusNotification::show()
{
if(!m_dbusInterface->isValid()) {
if (!m_dbusInterface->isValid()) {
emit error();
return false;
}
delete m_watcher;
m_watcher = new QDBusPendingCallWatcher(m_dbusInterface->Notify(QCoreApplication::applicationName(), m_id, m_icon, m_title, m_msg, m_actions, m_hints, m_timeout), this);
m_watcher = new QDBusPendingCallWatcher(
m_dbusInterface->Notify(QCoreApplication::applicationName(), m_id, m_icon, m_title, m_msg, m_actions, m_hints, m_timeout), this);
connect(m_watcher, &QDBusPendingCallWatcher::finished, this, &DBusNotification::handleNotifyResult);
return true;
}
@ -160,10 +164,10 @@ bool DBusNotification::show(const QString &message)
*/
bool DBusNotification::update(const QString &line)
{
if(!isVisible() || m_msg.isEmpty()) {
if (!isVisible() || m_msg.isEmpty()) {
m_msg = line;
} else {
if(!m_msg.startsWith(QStringLiteral(""))) {
if (!m_msg.startsWith(QStringLiteral(""))) {
m_msg.insert(0, QStringLiteral(""));
}
m_msg.append(QStringLiteral("\n"));
@ -178,7 +182,7 @@ bool DBusNotification::update(const QString &line)
*/
void DBusNotification::hide()
{
if(m_id) {
if (m_id) {
m_dbusInterface->CloseNotification(m_id);
}
}
@ -188,7 +192,7 @@ void DBusNotification::hide()
*/
void DBusNotification::handleNotifyResult(QDBusPendingCallWatcher *watcher)
{
if(watcher != m_watcher) {
if (watcher != m_watcher) {
return;
}
@ -211,7 +215,7 @@ void DBusNotification::handleNotifyResult(QDBusPendingCallWatcher *watcher)
void DBusNotification::handleNotificationClosed(uint id, uint reason)
{
auto i = pendingNotifications.find(id);
if(i != pendingNotifications.end()) {
if (i != pendingNotifications.end()) {
DBusNotification *notification = i->second;
notification->m_id = 0;
emit notification->closed(reason >= 1 && reason <= 3 ? static_cast<NotificationCloseReason>(reason) : NotificationCloseReason::Undefined);
@ -225,7 +229,7 @@ void DBusNotification::handleNotificationClosed(uint id, uint reason)
void DBusNotification::handleActionInvoked(uint id, const QString &action)
{
auto i = pendingNotifications.find(id);
if(i != pendingNotifications.end()) {
if (i != pendingNotifications.end()) {
DBusNotification *notification = i->second;
emit notification->actionInvoked(action);
// Plasma 5 also closes the notification but doesn't emit the NotificationClose signal
@ -286,5 +290,4 @@ void DBusNotification::handleActionInvoked(uint id, const QString &action)
* \fn DBusNotification::isVisible()
* \brief Returns whether the notification is (still) visible.
*/
}

View File

@ -12,25 +12,11 @@ class OrgFreedesktopNotificationsInterface;
namespace MiscUtils {
enum class NotificationIcon
{
NoIcon,
Information,
Warning,
Critical
};
enum class NotificationIcon { NoIcon, Information, Warning, Critical };
enum class NotificationCloseReason
{
Undefined,
Expired,
Dismissed,
Manually,
ActionInvoked
};
enum class NotificationCloseReason { Undefined, Expired, Dismissed, Manually, ActionInvoked };
class QT_UTILITIES_EXPORT DBusNotification : public QObject
{
class QT_UTILITIES_EXPORT DBusNotification : public QObject {
Q_OBJECT
Q_PROPERTY(QString title READ title WRITE setTitle)
Q_PROPERTY(QString message READ message WRITE setMessage)
@ -40,7 +26,8 @@ class QT_UTILITIES_EXPORT DBusNotification : public QObject
Q_PROPERTY(bool visible READ isVisible)
public:
explicit DBusNotification(const QString &title, NotificationIcon icon = NotificationIcon::Information, int timeout = 10000, QObject *parent = nullptr);
explicit DBusNotification(
const QString &title, NotificationIcon icon = NotificationIcon::Information, int timeout = 10000, QObject *parent = nullptr);
explicit DBusNotification(const QString &title, const QString &icon, int timeout = 10000, QObject *parent = nullptr);
~DBusNotification();
@ -170,7 +157,6 @@ inline bool DBusNotification::isVisible() const
{
return m_id != 0;
}
}
#endif // MISC_UTILS_NOTIFICATION_H

View File

@ -25,5 +25,4 @@ bool openLocalFileOrDir(const QString &path)
return QDesktopServices::openUrl(url);
#endif
}
}

View File

@ -10,7 +10,6 @@ QT_FORWARD_DECLARE_CLASS(QString)
namespace DesktopUtils {
bool QT_UTILITIES_EXPORT openLocalFileOrDir(const QString &path);
}
#endif // DESKTOP_UTILS_DESKTOPSERVICES_H

View File

@ -1,20 +1,20 @@
#include "./dialogutils.h"
#if !defined(QT_UTILITIES_GUI_QTWIDGETS) && !defined(QT_UTILITIES_GUI_QTQUICK)
# include <QCoreApplication>
#include <QCoreApplication>
#else
# include <QGuiApplication>
# include <QPalette>
# include <QWidget>
# include <QStyle>
# ifdef QT_UTILITIES_GUI_QTWIDGETS
# include <QApplication>
# include <QDesktopWidget>
# include <QCursor>
# endif
#include <QGuiApplication>
#include <QPalette>
#include <QStyle>
#include <QWidget>
#ifdef QT_UTILITIES_GUI_QTWIDGETS
#include <QApplication>
#include <QCursor>
#include <QDesktopWidget>
#endif
#endif
#include <QFileInfo>
#include <QDir>
#include <QFileInfo>
namespace Dialogs {
@ -24,20 +24,22 @@ namespace Dialogs {
*/
QString generateWindowTitle(DocumentStatus documentStatus, const QString &documentPath)
{
switch(documentStatus) {
switch (documentStatus) {
case DocumentStatus::Saved:
if(documentPath.isEmpty()) {
if (documentPath.isEmpty()) {
return QCoreApplication::translate("Utilities::windowTitle", "Unsaved - %1").arg(QCoreApplication::applicationName());
} else {
QFileInfo file(documentPath);
return QCoreApplication::translate("Utilities::windowTitle", "%1 - %2 - %3").arg(file.fileName(), file.dir().path(), QCoreApplication::applicationName());
return QCoreApplication::translate("Utilities::windowTitle", "%1 - %2 - %3")
.arg(file.fileName(), file.dir().path(), QCoreApplication::applicationName());
}
case DocumentStatus::Unsaved:
if(documentPath.isEmpty()) {
if (documentPath.isEmpty()) {
return QCoreApplication::translate("Utilities::windowTitle", "*Unsaved - %1").arg(QCoreApplication::applicationName());
} else {
QFileInfo file(documentPath);
return QCoreApplication::translate("Utilities::windowTitle", "*%1 - %2 - %3").arg(file.fileName(), file.dir().path(), QCoreApplication::applicationName());
return QCoreApplication::translate("Utilities::windowTitle", "*%1 - %2 - %3")
.arg(file.fileName(), file.dir().path(), QCoreApplication::applicationName());
}
case DocumentStatus::NoDocument:
return QCoreApplication::applicationName();
@ -48,7 +50,7 @@ QString generateWindowTitle(DocumentStatus documentStatus, const QString &docume
#if defined(QT_UTILITIES_GUI_QTWIDGETS) || defined(QT_UTILITIES_GUI_QTQUICK)
# ifdef Q_OS_WIN32
#ifdef Q_OS_WIN32
/*!
* \brief Returns the color used to draw frames.
@ -67,27 +69,28 @@ QColor instructionTextColor()
return (baseColor.value() > 204 && baseColor.saturation() < 63) ? QColor(0x00, 0x33, 0x99) : QGuiApplication::palette().text().color();
}
# endif
#endif
/*!
* \brief Returns the stylesheet for dialogs and other windows used in my applications.
*/
const QString &dialogStyle()
{
# ifdef Q_OS_WIN32
static const auto style = QStringLiteral("#mainWidget { color: palette(text); background-color: palette(base); border: none; }"
"#bottomWidget { background-color: palette(window); color: palette(window-text); border-top: 1px solid %1; }"
"QMessageBox QLabel, QInputDialog QLabel, *[classNames~=\"heading\"] { font-size: 12pt; color: %2; }"
"*[classNames~=\"input-invalid\"] { color: red; }").arg(
windowFrameColor().name(), instructionTextColor().name());
# else
#ifdef Q_OS_WIN32
static const auto style
= QStringLiteral("#mainWidget { color: palette(text); background-color: palette(base); border: none; }"
"#bottomWidget { background-color: palette(window); color: palette(window-text); border-top: 1px solid %1; }"
"QMessageBox QLabel, QInputDialog QLabel, *[classNames~=\"heading\"] { font-size: 12pt; color: %2; }"
"*[classNames~=\"input-invalid\"] { color: red; }")
.arg(windowFrameColor().name(), instructionTextColor().name());
#else
static const auto style = QStringLiteral("*[classNames~=\"heading\"] { font-weight: bold; }"
"*[classNames~=\"input-invalid\"] { color: red; }");
# endif
#endif
return style;
}
# ifdef QT_UTILITIES_GUI_QTWIDGETS
#ifdef QT_UTILITIES_GUI_QTWIDGETS
/*!
* \brief Moves the specified \a widget in the middle of the (available) screen area. If there are multiple
@ -96,13 +99,7 @@ const QString &dialogStyle()
void centerWidget(QWidget *widget)
{
widget->setGeometry(
QStyle::alignedRect(
Qt::LeftToRight,
Qt::AlignCenter,
widget->size(),
QApplication::desktop()->availableGeometry(QCursor::pos())
)
);
QStyle::alignedRect(Qt::LeftToRight, Qt::AlignCenter, widget->size(), QApplication::desktop()->availableGeometry(QCursor::pos())));
}
/*!
@ -116,14 +113,7 @@ void cornerWidget(QWidget *widget)
Qt::Alignment alignment = 0;
alignment |= (cursorPos.x() - availableGeometry.left() < availableGeometry.right() - cursorPos.x() ? Qt::AlignLeft : Qt::AlignRight);
alignment |= (cursorPos.y() - availableGeometry.top() < availableGeometry.bottom() - cursorPos.y() ? Qt::AlignTop : Qt::AlignBottom);
widget->setGeometry(
QStyle::alignedRect(
Qt::LeftToRight,
alignment,
widget->size(),
availableGeometry
)
);
widget->setGeometry(QStyle::alignedRect(Qt::LeftToRight, alignment, widget->size(), availableGeometry));
}
/*!
@ -146,9 +136,8 @@ void updateStyle(QWidget *widget)
widget->update();
}
# endif
#endif
#endif
} // namespace Dialogs

View File

@ -22,18 +22,18 @@ enum class DocumentStatus {
QString QT_UTILITIES_EXPORT generateWindowTitle(DocumentStatus documentStatus, const QString &documentPath);
#if defined(QT_UTILITIES_GUI_QTWIDGETS) || defined (QT_UTILITIES_GUI_QTQUICK)
# ifdef Q_OS_WIN32
#if defined(QT_UTILITIES_GUI_QTWIDGETS) || defined(QT_UTILITIES_GUI_QTQUICK)
#ifdef Q_OS_WIN32
QColor QT_UTILITIES_EXPORT windowFrameColor();
QColor QT_UTILITIES_EXPORT instructionTextColor();
# endif
#endif
const QString QT_UTILITIES_EXPORT &dialogStyle();
# ifdef QT_UTILITIES_GUI_QTWIDGETS
#ifdef QT_UTILITIES_GUI_QTWIDGETS
void QT_UTILITIES_EXPORT centerWidget(QWidget *widget);
void QT_UTILITIES_EXPORT cornerWidget(QWidget *widget);
void QT_UTILITIES_EXPORT makeHeading(QWidget *widget);
void QT_UTILITIES_EXPORT updateStyle(QWidget *widget);
# endif
#endif
#endif
} // namespace Dialogs

View File

@ -1,12 +1,12 @@
#include "recentmenumanager.h"
#include <QStringList>
#include <QCoreApplication>
#include <QMenu>
#include <QAction>
#include <QCoreApplication>
#include <QFile>
#include <QMenu>
#include <QMessageBox>
#include <QPushButton>
#include <QFile>
#include <QStringList>
namespace MiscUtils {
@ -25,9 +25,9 @@ namespace MiscUtils {
* - The menu entries shouldn't be manipulated manually by the caller till the manager is destructed.
* - The manager does not take ownership over \a menu.
*/
RecentMenuManager::RecentMenuManager(QMenu *menu, QObject *parent) :
QObject(parent),
m_menu(menu)
RecentMenuManager::RecentMenuManager(QMenu *menu, QObject *parent)
: QObject(parent)
, m_menu(menu)
{
m_menu->clear();
m_menu->setTitle(tr("&Recent"));
@ -42,15 +42,15 @@ RecentMenuManager::RecentMenuManager(QMenu *menu, QObject *parent) :
void RecentMenuManager::restore(const QStringList &savedEntries)
{
QAction *action = nullptr;
for(const QString &path : savedEntries) {
if(!path.isEmpty()) {
for (const QString &path : savedEntries) {
if (!path.isEmpty()) {
action = new QAction(path, m_menu);
action->setProperty("file_path", path);
m_menu->insertAction(m_sep, action);
connect(action, &QAction::triggered, this, &RecentMenuManager::handleActionTriggered);
}
}
if(action) {
if (action) {
m_menu->actions().front()->setShortcut(QKeySequence(Qt::Key_F6));
m_menu->setEnabled(true);
}
@ -64,9 +64,9 @@ QStringList RecentMenuManager::save()
QStringList existingEntires;
QList<QAction *> entryActions = m_menu->actions();
existingEntires.reserve(entryActions.size());
for(const QAction *action : entryActions) {
for (const QAction *action : entryActions) {
QVariant path = action->property("file_path");
if(!path.isNull()) {
if (!path.isNull()) {
existingEntires << path.toString();
}
}
@ -81,17 +81,17 @@ void RecentMenuManager::addEntry(const QString &path)
QList<QAction *> existingEntries = m_menu->actions();
QAction *entry = nullptr;
// remove shortcut from existing entries
for(QAction *existingEntry : existingEntries) {
for (QAction *existingEntry : existingEntries) {
existingEntry->setShortcut(QKeySequence());
// check whether existing entry matches entry to add
if(existingEntry->property("file_path").toString() == path) {
if (existingEntry->property("file_path").toString() == path) {
entry = existingEntry;
break;
}
}
if(!entry) {
if (!entry) {
// remove old entries to have never more than 10 entries
for(int i = existingEntries.size() - 1; i > 8; --i) {
for (int i = existingEntries.size() - 1; i > 8; --i) {
delete existingEntries[i];
}
existingEntries = m_menu->actions();
@ -117,8 +117,8 @@ void RecentMenuManager::addEntry(const QString &path)
void RecentMenuManager::clearEntries()
{
QList<QAction *> entries = m_menu->actions();
for(auto i = entries.begin(), end = entries.end() - 2; i != end; ++i) {
if(*i != m_clearAction) {
for (auto i = entries.begin(), end = entries.end() - 2; i != end; ++i) {
if (*i != m_clearAction) {
delete *i;
}
}
@ -130,10 +130,10 @@ void RecentMenuManager::clearEntries()
*/
void RecentMenuManager::handleActionTriggered()
{
if(QAction *action = qobject_cast<QAction *>(sender())) {
if (QAction *action = qobject_cast<QAction *>(sender())) {
const QString path = action->property("file_path").toString();
if(!path.isEmpty()) {
if(QFile::exists(path)) {
if (!path.isEmpty()) {
if (QFile::exists(path)) {
emit fileSelected(path);
} else {
QMessageBox msg;
@ -144,10 +144,10 @@ void RecentMenuManager::handleActionTriggered()
QPushButton *deleteEntryButton = msg.addButton(tr("delete entry"), QMessageBox::YesRole);
msg.setEscapeButton(keepEntryButton);
msg.exec();
if(msg.clickedButton() == deleteEntryButton) {
if (msg.clickedButton() == deleteEntryButton) {
delete action;
QList<QAction *> remainingActions = m_menu->actions();
if(!remainingActions.isEmpty() && remainingActions.front() != m_sep && remainingActions.front() != m_clearAction) {
if (!remainingActions.isEmpty() && remainingActions.front() != m_sep && remainingActions.front() != m_clearAction) {
remainingActions.front()->setShortcut(QKeySequence(Qt::Key_F6));
m_menu->setEnabled(true);
} else {
@ -164,5 +164,4 @@ void RecentMenuManager::handleActionTriggered()
* \brief Emitted after the user selected a file.
* \remarks Only emitted when the selected file still existed; otherwise the user is ask whether to keep or delete the entry.
*/
}

View File

@ -10,8 +10,7 @@ QT_FORWARD_DECLARE_CLASS(QAction)
namespace MiscUtils {
class QT_UTILITIES_EXPORT RecentMenuManager : public QObject
{
class QT_UTILITIES_EXPORT RecentMenuManager : public QObject {
Q_OBJECT
public:
@ -34,7 +33,6 @@ private:
QAction *m_sep;
QAction *m_clearAction;
};
}
#endif // MISC_UTILS_RECENTMENUMANAGER_H

View File

@ -10,16 +10,15 @@ namespace ThreadingUtils {
/*!
* \brief Like QMutexLocker, but it just tries to lock the mutex.
*/
template<typename Mutex = QMutex>
class TryLocker
{
template <typename Mutex = QMutex> class TryLocker {
public:
/*!
* \brief Tries to lock the specified mutex.
*/
TryLocker(Mutex &mutex) :
m_mutex(mutex.tryLock() ? &mutex : nullptr)
{}
TryLocker(Mutex &mutex)
: m_mutex(mutex.tryLock() ? &mutex : nullptr)
{
}
/*!
* \brief Unlocks the mutex specified when constructing.
@ -27,7 +26,7 @@ public:
*/
~TryLocker()
{
if(m_mutex) {
if (m_mutex) {
m_mutex->unlock();
}
}
@ -51,7 +50,6 @@ public:
private:
Mutex *m_mutex;
};
}
#endif // THREADING_UTILS_TRYLOCKER_H

View File

@ -5,20 +5,20 @@
*/
#ifdef iftag
# undef iftag
#undef iftag
#endif
#ifdef eliftag
# undef eliftag
#undef eliftag
#endif
#ifdef else_skip
# undef else_skip
#undef else_skip
#endif
#ifdef children
# undef children
#undef children
#endif
#ifdef text
# undef text
#undef text
#endif
#ifdef attribute
# undef attribute
#undef attribute
#endif

View File

@ -7,10 +7,16 @@
// ensure there are no conflicting macros defined
#include "./undefxmlparsermacros.h"
#define iftag(tagName) if(xmlReader.name() == QLatin1String(tagName))
#define eliftag(tagName) else if(xmlReader.name() == QLatin1String(tagName))
#define else_skip else { xmlReader.skipCurrentElement(); }
#define children while(xmlReader.readNextStartElement())
#define iftag(tagName) if (xmlReader.name() == QLatin1String(tagName))
#define eliftag(tagName) else if (xmlReader.name() == QLatin1String(tagName))
#define else_skip \
else \
{ \
xmlReader.skipCurrentElement(); \
}
#define children while (xmlReader.readNextStartElement())
#define text (xmlReader.readElementText(QXmlStreamReader::ErrorOnUnexpectedElement))
#define attribute(attributeName) (xmlReader.attributes().value(QLatin1String(attributeName)))
#define attributeFlag(attributeName) (xmlReader.attributes().hasAttribute(QLatin1String(attributeName)) && xmlReader.attributes().value(QLatin1String(attributeName)) != QLatin1String("false"))
#define attributeFlag(attributeName) \
(xmlReader.attributes().hasAttribute(QLatin1String(attributeName)) \
&& xmlReader.attributes().value(QLatin1String(attributeName)) != QLatin1String("false"))

View File

@ -22,13 +22,14 @@ namespace Models {
/*!
* \brief Constructs a new checklist model.
*/
ChecklistModel::ChecklistModel(QObject *parent) :
QAbstractListModel(parent)
{}
ChecklistModel::ChecklistModel(QObject *parent)
: QAbstractListModel(parent)
{
}
int ChecklistModel::rowCount(const QModelIndex &parent) const
{
if(!parent.isValid()) {
if (!parent.isValid()) {
return m_items.size();
}
return 0;
@ -36,7 +37,7 @@ int ChecklistModel::rowCount(const QModelIndex &parent) const
Qt::ItemFlags ChecklistModel::flags(const QModelIndex &index) const
{
if(!index.isValid() || index.row() >= m_items.count() || index.model() != this) {
if (!index.isValid() || index.row() >= m_items.count() || index.model() != this) {
return Qt::ItemIsDropEnabled; // allows drops outside the items
}
return QAbstractListModel::flags(index) | Qt::ItemIsUserCheckable | Qt::ItemIsDragEnabled;
@ -44,16 +45,15 @@ Qt::ItemFlags ChecklistModel::flags(const QModelIndex &index) const
QVariant ChecklistModel::data(const QModelIndex &index, int role) const
{
if(index.isValid() && index.row() < m_items.size()) {
switch(role) {
if (index.isValid() && index.row() < m_items.size()) {
switch (role) {
case Qt::DisplayRole:
return m_items.at(index.row()).label();
case Qt::CheckStateRole:
return m_items.at(index.row()).checkState();
case idRole():
return m_items.at(index.row()).id();
default:
;
default:;
}
}
return QVariant();
@ -73,14 +73,14 @@ bool ChecklistModel::setData(const QModelIndex &index, const QVariant &value, in
bool success = false;
QVector<int> roles;
roles << role;
if(index.isValid() && index.row() < m_items.size()) {
switch(role) {
if (index.isValid() && index.row() < m_items.size()) {
switch (role) {
case Qt::DisplayRole:
m_items[index.row()].m_label = value.toString();
success = true;
break;
case Qt::CheckStateRole:
if(value.canConvert(QMetaType::Int)) {
if (value.canConvert(QMetaType::Int)) {
m_items[index.row()].m_checkState = static_cast<Qt::CheckState>(value.toInt());
success = true;
}
@ -89,16 +89,16 @@ bool ChecklistModel::setData(const QModelIndex &index, const QVariant &value, in
m_items[index.row()].m_id = value;
success = true;
QString label = labelForId(value);
if(!label.isEmpty()) {
if (!label.isEmpty()) {
m_items[index.row()].m_label = label;
roles << Qt::DisplayRole;
}
break;
} default:
;
}
default:;
}
}
if(success) {
if (success) {
dataChanged(index, index, roles);
}
return success;
@ -106,7 +106,7 @@ bool ChecklistModel::setData(const QModelIndex &index, const QVariant &value, in
bool ChecklistModel::setItemData(const QModelIndex &index, const QMap<int, QVariant> &roles)
{
for(QMap<int, QVariant>::ConstIterator it = roles.constBegin(); it != roles.constEnd(); ++it) {
for (QMap<int, QVariant>::ConstIterator it = roles.constBegin(); it != roles.constEnd(); ++it) {
setData(index, it.value(), it.key());
}
return true;
@ -138,7 +138,7 @@ bool ChecklistModel::insertRows(int row, int count, const QModelIndex &parent)
return false;
}
beginInsertRows(QModelIndex(), row, row + count - 1);
for(int index = row, end = row + count; index < end; ++index) {
for (int index = row, end = row + count; index < end; ++index) {
m_items.insert(index, ChecklistItem());
}
endInsertRows();
@ -151,7 +151,7 @@ bool ChecklistModel::removeRows(int row, int count, const QModelIndex &parent)
return false;
}
beginRemoveRows(QModelIndex(), row, row + count - 1);
for(int index = row, end = row + count; index < end; ++index) {
for (int index = row, end = row + count; index < end; ++index) {
m_items.removeAt(index);
}
endRemoveRows();
@ -185,18 +185,18 @@ void ChecklistModel::restore(QSettings &settings, const QString &name)
m_items.clear();
int rows = settings.beginReadArray(name);
m_items.reserve(rows);
for(int i = 0; i < rows; ++i) {
for (int i = 0; i < rows; ++i) {
settings.setArrayIndex(i);
QVariant id = settings.value(QStringLiteral("id"));
QVariant selected = settings.value(QStringLiteral("selected"));
if(!id.isNull() && !selected.isNull() && selected.canConvert(QMetaType::Bool) && !restoredIds.contains(id)) {
if (!id.isNull() && !selected.isNull() && selected.canConvert(QMetaType::Bool) && !restoredIds.contains(id)) {
m_items << ChecklistItem(id, labelForId(id), selected.toBool() ? Qt::Checked : Qt::Unchecked);
restoredIds << id;
}
}
settings.endArray();
for(const ChecklistItem &item : currentItems) {
if(!restoredIds.contains(item.id())) {
for (const ChecklistItem &item : currentItems) {
if (!restoredIds.contains(item.id())) {
m_items << item;
}
}
@ -214,7 +214,7 @@ void ChecklistModel::save(QSettings &settings, const QString &name) const
{
settings.beginWriteArray(name, m_items.size());
int index = 0;
for(const ChecklistItem &item : m_items) {
for (const ChecklistItem &item : m_items) {
settings.setArrayIndex(index);
settings.setValue(QStringLiteral("id"), item.id());
settings.setValue(QStringLiteral("selected"), item.isChecked());
@ -222,5 +222,4 @@ void ChecklistModel::save(QSettings &settings, const QString &name) const
}
settings.endArray();
}
}

View File

@ -12,8 +12,7 @@ namespace Models {
class ChecklistModel;
class QT_UTILITIES_EXPORT ChecklistItem
{
class QT_UTILITIES_EXPORT ChecklistItem {
friend class ChecklistModel;
public:
@ -30,11 +29,12 @@ private:
Qt::CheckState m_checkState;
};
inline ChecklistItem::ChecklistItem(const QVariant &id, const QString &label, Qt::CheckState checkState) :
m_id(id),
m_label(label),
m_checkState(checkState)
{}
inline ChecklistItem::ChecklistItem(const QVariant &id, const QString &label, Qt::CheckState checkState)
: m_id(id)
, m_label(label)
, m_checkState(checkState)
{
}
/*!
* \brief Returns the ID of the item.
@ -69,8 +69,7 @@ inline bool ChecklistItem::isChecked() const
return m_checkState == Qt::Checked;
}
class QT_UTILITIES_EXPORT ChecklistModel : public QAbstractListModel
{
class QT_UTILITIES_EXPORT ChecklistModel : public QAbstractListModel {
Q_OBJECT
public:
explicit ChecklistModel(QObject *parent = nullptr);
@ -93,7 +92,6 @@ public:
private:
QList<ChecklistItem> m_items;
};
/*!
@ -111,7 +109,6 @@ inline constexpr int ChecklistModel::idRole()
{
return Qt::UserRole + 1;
}
}
#endif // MODELS_CHECKLISTMODEL_H

View File

@ -1,11 +1,11 @@
#include "./colorbutton.h"
#include <QColorDialog>
#include <QPainter>
#include <QMimeData>
#include <QDragEnterEvent>
#include <QDrag>
#include <QApplication>
#include <QColorDialog>
#include <QDrag>
#include <QDragEnterEvent>
#include <QMimeData>
#include <QPainter>
namespace Widgets {
@ -13,8 +13,7 @@ namespace Widgets {
* \cond
*/
class ColorButtonPrivate
{
class ColorButtonPrivate {
ColorButton *q_ptr;
Q_DECLARE_PUBLIC(ColorButton)
public:
@ -71,9 +70,7 @@ QPixmap ColorButtonPrivate::generatePixmap() const
p.setBrushOrigin((r.width() % pixSize + pixSize) / 2 + corr, (r.height() % pixSize + pixSize) / 2 + corr);
p.fillRect(r, br);
p.fillRect(r.width() / 4 + corr, r.height() / 4 + corr,
r.width() / 2, r.height() / 2,
QColor(shownColor().rgb()));
p.fillRect(r.width() / 4 + corr, r.height() / 4 + corr, r.width() / 2, r.height() / 2, QColor(shownColor().rgb()));
p.drawRect(pix.rect().adjusted(0, 0, -1, -1));
return pix;
@ -84,7 +81,8 @@ QPixmap ColorButtonPrivate::generatePixmap() const
*/
ColorButton::ColorButton(QWidget *parent)
: QToolButton(parent), d_ptr(new ColorButtonPrivate)
: QToolButton(parent)
, d_ptr(new ColorButtonPrivate)
{
d_ptr->q_ptr = this;
d_ptr->m_dragging = false;
@ -187,8 +185,7 @@ void ColorButton::mousePressEvent(QMouseEvent *event)
void ColorButton::mouseMoveEvent(QMouseEvent *event)
{
#ifndef QT_NO_DRAGANDDROP
if (event->buttons() & Qt::LeftButton &&
(d_ptr->m_dragStart - event->pos()).manhattanLength() > QApplication::startDragDistance()) {
if (event->buttons() & Qt::LeftButton && (d_ptr->m_dragStart - event->pos()).manhattanLength() > QApplication::startDragDistance()) {
QMimeData *mime = new QMimeData;
mime->setColorData(color());
QDrag *drg = new QDrag(this);
@ -233,7 +230,6 @@ void ColorButton::dropEvent(QDropEvent *event)
emit colorChanged(color());
}
#endif
}
#include "moc_colorbutton.cpp"

View File

@ -12,8 +12,7 @@ namespace Widgets {
*
* This is taken from qttools/src/shared/qtgradienteditor/qtcolorbutton.h.
*/
class QT_UTILITIES_EXPORT ColorButton : public QToolButton
{
class QT_UTILITIES_EXPORT ColorButton : public QToolButton {
Q_OBJECT
Q_PROPERTY(bool backgroundCheckered READ isBackgroundCheckered WRITE setBackgroundCheckered)
public:
@ -47,7 +46,6 @@ private:
Q_DISABLE_COPY(ColorButton)
Q_PRIVATE_SLOT(d_func(), void slotEditColor())
};
}
#endif // WIDGETS_COLORBUTTON_H

View File

@ -3,11 +3,11 @@
#include "ui_paletteeditor.h"
#include <QHeaderView>
#include <QLabel>
#include <QMetaProperty>
#include <QPainter>
#include <QToolButton>
#include <QLabel>
#include <QHeaderView>
using namespace Widgets;
@ -15,14 +15,14 @@ namespace Dialogs {
enum { BrushRole = 33 };
PaletteEditor::PaletteEditor(QWidget *parent) :
QDialog(parent),
m_ui(new Ui::PaletteEditor),
m_currentColorGroup(QPalette::Active),
m_paletteModel(new PaletteModel(this)),
m_modelUpdated(false),
m_paletteUpdated(false),
m_compute(true)
PaletteEditor::PaletteEditor(QWidget *parent)
: QDialog(parent)
, m_ui(new Ui::PaletteEditor)
, m_currentColorGroup(QPalette::Active)
, m_paletteModel(new PaletteModel(this))
, m_modelUpdated(false)
, m_paletteUpdated(false)
, m_compute(true)
{
m_ui->setupUi(this);
m_ui->paletteView->setModel(m_paletteModel);
@ -32,8 +32,7 @@ PaletteEditor::PaletteEditor(QWidget *parent) :
ColorDelegate *delegate = new ColorDelegate(this);
m_ui->paletteView->setItemDelegate(delegate);
m_ui->paletteView->setEditTriggers(QAbstractItemView::AllEditTriggers);
connect(m_paletteModel, &PaletteModel::paletteChanged,
this, &PaletteEditor::paletteChanged);
connect(m_paletteModel, &PaletteModel::paletteChanged, this, &PaletteEditor::paletteChanged);
m_ui->paletteView->setSelectionBehavior(QAbstractItemView::SelectRows);
m_ui->paletteView->setDragEnabled(true);
m_ui->paletteView->setDropIndicatorShown(true);
@ -43,7 +42,8 @@ PaletteEditor::PaletteEditor(QWidget *parent) :
}
PaletteEditor::~PaletteEditor()
{}
{
}
QPalette PaletteEditor::palette() const
{
@ -56,12 +56,12 @@ void PaletteEditor::setPalette(const QPalette &palette)
const uint mask = palette.resolve();
for (int i = 0; i < (int)QPalette::NColorRoles; i++) {
if (!(mask & (1 << i))) {
m_editPalette.setBrush(QPalette::Active, static_cast<QPalette::ColorRole>(i),
m_parentPalette.brush(QPalette::Active, static_cast<QPalette::ColorRole>(i)));
m_editPalette.setBrush(
QPalette::Active, static_cast<QPalette::ColorRole>(i), m_parentPalette.brush(QPalette::Active, static_cast<QPalette::ColorRole>(i)));
m_editPalette.setBrush(QPalette::Inactive, static_cast<QPalette::ColorRole>(i),
m_parentPalette.brush(QPalette::Inactive, static_cast<QPalette::ColorRole>(i)));
m_parentPalette.brush(QPalette::Inactive, static_cast<QPalette::ColorRole>(i)));
m_editPalette.setBrush(QPalette::Disabled, static_cast<QPalette::ColorRole>(i),
m_parentPalette.brush(QPalette::Disabled, static_cast<QPalette::ColorRole>(i)));
m_parentPalette.brush(QPalette::Disabled, static_cast<QPalette::ColorRole>(i)));
}
}
m_editPalette.resolve(mask);
@ -149,7 +149,7 @@ void PaletteEditor::updatePreviewPalette()
// build the preview palette
const QPalette currentPalette = palette();
QPalette previewPalette;
for(int i = QPalette::WindowText; i < QPalette::NColorRoles; ++i) {
for (int i = QPalette::WindowText; i < QPalette::NColorRoles; ++i) {
const QPalette::ColorRole r = static_cast<QPalette::ColorRole>(i);
const QBrush br = currentPalette.brush(g, r);
previewPalette.setBrush(QPalette::Active, r, br);
@ -163,35 +163,35 @@ void PaletteEditor::updateStyledButton()
m_ui->buildButton->setColor(palette().color(QPalette::Active, QPalette::Button));
}
QPalette PaletteEditor::getPalette(QWidget *parent, const QPalette &init,
const QPalette &parentPal, int *ok)
QPalette PaletteEditor::getPalette(QWidget *parent, const QPalette &init, const QPalette &parentPal, int *ok)
{
PaletteEditor dlg(parent);
QPalette parentPalette(parentPal);
uint mask = init.resolve();
for (int i = 0; i < (int)QPalette::NColorRoles; ++i) {
if (!(mask & (1 << i))) {
parentPalette.setBrush(QPalette::Active, static_cast<QPalette::ColorRole>(i),
init.brush(QPalette::Active, static_cast<QPalette::ColorRole>(i)));
parentPalette.setBrush(QPalette::Inactive, static_cast<QPalette::ColorRole>(i),
init.brush(QPalette::Inactive, static_cast<QPalette::ColorRole>(i)));
parentPalette.setBrush(QPalette::Disabled, static_cast<QPalette::ColorRole>(i),
init.brush(QPalette::Disabled, static_cast<QPalette::ColorRole>(i)));
parentPalette.setBrush(
QPalette::Active, static_cast<QPalette::ColorRole>(i), init.brush(QPalette::Active, static_cast<QPalette::ColorRole>(i)));
parentPalette.setBrush(
QPalette::Inactive, static_cast<QPalette::ColorRole>(i), init.brush(QPalette::Inactive, static_cast<QPalette::ColorRole>(i)));
parentPalette.setBrush(
QPalette::Disabled, static_cast<QPalette::ColorRole>(i), init.brush(QPalette::Disabled, static_cast<QPalette::ColorRole>(i)));
}
}
dlg.setPalette(init, parentPalette);
const int result = dlg.exec();
if (ok) *ok = result;
if (ok)
*ok = result;
return result == QDialog::Accepted ? dlg.palette() : init;
}
//////////////////////
PaletteModel::PaletteModel(QObject *parent) :
QAbstractTableModel(parent),
m_compute(true)
PaletteModel::PaletteModel(QObject *parent)
: QAbstractTableModel(parent)
, m_compute(true)
{
const QMetaObject *meta = metaObject();
const int index = meta->indexOfProperty("colorRole");
@ -233,8 +233,7 @@ QVariant PaletteModel::data(const QModelIndex &index, int role) const
return QVariant();
}
if (role == BrushRole)
return m_palette.brush(columnToGroup(index.column()),
static_cast<QPalette::ColorRole>(index.row()));
return m_palette.brush(columnToGroup(index.column()), static_cast<QPalette::ColorRole>(index.row()));
return QVariant();
}
@ -254,30 +253,30 @@ bool PaletteModel::setData(const QModelIndex &index, const QVariant &value, int
if (m_compute) {
m_palette.setBrush(QPalette::Inactive, r, br);
switch (r) {
case QPalette::WindowText:
case QPalette::Text:
case QPalette::ButtonText:
case QPalette::Base:
break;
case QPalette::Dark:
m_palette.setBrush(QPalette::Disabled, QPalette::WindowText, br);
m_palette.setBrush(QPalette::Disabled, QPalette::Dark, br);
m_palette.setBrush(QPalette::Disabled, QPalette::Text, br);
m_palette.setBrush(QPalette::Disabled, QPalette::ButtonText, br);
idxBegin = PaletteModel::index(0, 0);
idxEnd = PaletteModel::index(m_roleNames.count() - 1, 3);
break;
case QPalette::Window:
m_palette.setBrush(QPalette::Disabled, QPalette::Base, br);
m_palette.setBrush(QPalette::Disabled, QPalette::Window, br);
idxBegin = PaletteModel::index(QPalette::Base, 0);
break;
case QPalette::Highlight:
//m_palette.setBrush(QPalette::Disabled, QPalette::Highlight, c.dark(120));
break;
default:
m_palette.setBrush(QPalette::Disabled, r, br);
break;
case QPalette::WindowText:
case QPalette::Text:
case QPalette::ButtonText:
case QPalette::Base:
break;
case QPalette::Dark:
m_palette.setBrush(QPalette::Disabled, QPalette::WindowText, br);
m_palette.setBrush(QPalette::Disabled, QPalette::Dark, br);
m_palette.setBrush(QPalette::Disabled, QPalette::Text, br);
m_palette.setBrush(QPalette::Disabled, QPalette::ButtonText, br);
idxBegin = PaletteModel::index(0, 0);
idxEnd = PaletteModel::index(m_roleNames.count() - 1, 3);
break;
case QPalette::Window:
m_palette.setBrush(QPalette::Disabled, QPalette::Base, br);
m_palette.setBrush(QPalette::Disabled, QPalette::Window, br);
idxBegin = PaletteModel::index(QPalette::Base, 0);
break;
case QPalette::Highlight:
//m_palette.setBrush(QPalette::Disabled, QPalette::Highlight, c.dark(120));
break;
default:
m_palette.setBrush(QPalette::Disabled, r, br);
break;
}
}
emit paletteChanged(m_palette);
@ -291,12 +290,12 @@ bool PaletteModel::setData(const QModelIndex &index, const QVariant &value, int
if (isMask)
mask |= (1 << r);
else {
m_palette.setBrush(QPalette::Active, static_cast<QPalette::ColorRole>(r),
m_parentPalette.brush(QPalette::Active, static_cast<QPalette::ColorRole>(r)));
m_palette.setBrush(
QPalette::Active, static_cast<QPalette::ColorRole>(r), m_parentPalette.brush(QPalette::Active, static_cast<QPalette::ColorRole>(r)));
m_palette.setBrush(QPalette::Inactive, static_cast<QPalette::ColorRole>(r),
m_parentPalette.brush(QPalette::Inactive, static_cast<QPalette::ColorRole>(r)));
m_parentPalette.brush(QPalette::Inactive, static_cast<QPalette::ColorRole>(r)));
m_palette.setBrush(QPalette::Disabled, static_cast<QPalette::ColorRole>(r),
m_parentPalette.brush(QPalette::Disabled, static_cast<QPalette::ColorRole>(r)));
m_parentPalette.brush(QPalette::Disabled, static_cast<QPalette::ColorRole>(r)));
mask &= ~(1 << index.row());
}
@ -316,8 +315,7 @@ Qt::ItemFlags PaletteModel::flags(const QModelIndex &index) const
return Qt::ItemIsEditable | Qt::ItemIsEnabled;
}
QVariant PaletteModel::headerData(int section, Qt::Orientation orientation,
int role) const
QVariant PaletteModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if (orientation == Qt::Horizontal && role == Qt::DisplayRole) {
if (section == 0)
@ -366,10 +364,10 @@ int PaletteModel::groupToColumn(QPalette::ColorGroup group) const
//////////////////////////
BrushEditor::BrushEditor(QWidget *parent) :
QWidget(parent),
m_button(new ColorButton(this)),
m_changed(false)
BrushEditor::BrushEditor(QWidget *parent)
: QWidget(parent)
, m_button(new ColorButton(this))
, m_changed(false)
{
QLayout *layout = new QHBoxLayout(this);
layout->setMargin(0);
@ -402,10 +400,10 @@ bool BrushEditor::changed() const
//////////////////////////
RoleEditor::RoleEditor(QWidget *parent) :
QWidget(parent),
m_label(new QLabel(this)),
m_edited(false)
RoleEditor::RoleEditor(QWidget *parent)
: QWidget(parent)
, m_label(new QLabel(this))
, m_edited(false)
{
QHBoxLayout *layout = new QHBoxLayout(this);
layout->setMargin(0);
@ -419,7 +417,7 @@ RoleEditor::RoleEditor(QWidget *parent) :
QToolButton *button = new QToolButton(this);
button->setToolButtonStyle(Qt::ToolButtonIconOnly);
button->setIcon(QIcon(QStringLiteral(":/qtutilities/icons/hicolor/48x48/actions/edit-clear.png")));
button->setIconSize(QSize(8,8));
button->setIconSize(QSize(8, 8));
button->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::MinimumExpanding));
layout->addWidget(button);
connect(button, &QAbstractButton::clicked, this, &RoleEditor::emitResetProperty);
@ -452,8 +450,8 @@ void RoleEditor::emitResetProperty()
}
//////////////////////////
ColorDelegate::ColorDelegate(QObject *parent) :
QItemDelegate(parent)
ColorDelegate::ColorDelegate(QObject *parent)
: QItemDelegate(parent)
{
}
@ -470,8 +468,7 @@ QWidget *ColorDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem
typedef void (BrushEditor::*BrushEditorWidgetSignal)(QWidget *);
BrushEditor *editor = new BrushEditor(parent);
connect(editor, static_cast<BrushEditorWidgetSignal>(&BrushEditor::changed),
this, &ColorDelegate::commitData);
connect(editor, static_cast<BrushEditorWidgetSignal>(&BrushEditor::changed), this, &ColorDelegate::commitData);
editor->setFocusPolicy(Qt::NoFocus);
editor->installEventFilter(const_cast<ColorDelegate *>(this));
ed = editor;
@ -494,8 +491,7 @@ void ColorDelegate::setEditorData(QWidget *ed, const QModelIndex &index) const
}
}
void ColorDelegate::setModelData(QWidget *ed, QAbstractItemModel *model,
const QModelIndex &index) const
void ColorDelegate::setModelData(QWidget *ed, QAbstractItemModel *model, const QModelIndex &index) const
{
if (index.column() == 0) {
RoleEditor *editor = static_cast<RoleEditor *>(ed);
@ -510,8 +506,7 @@ void ColorDelegate::setModelData(QWidget *ed, QAbstractItemModel *model,
}
}
void ColorDelegate::updateEditorGeometry(QWidget *ed,
const QStyleOptionViewItem &option, const QModelIndex &index) const
void ColorDelegate::updateEditorGeometry(QWidget *ed, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
QItemDelegate::updateEditorGeometry(ed, option, index);
ed->setGeometry(ed->geometry().adjusted(0, 0, -1, -1));
@ -525,9 +520,7 @@ void ColorDelegate::paint(QPainter *painter, const QStyleOptionViewItem &opt, co
option.font.setBold(true);
}
QBrush br = qvariant_cast<QBrush>(index.model()->data(index, BrushRole));
if (br.style() == Qt::LinearGradientPattern ||
br.style() == Qt::RadialGradientPattern ||
br.style() == Qt::ConicalGradientPattern) {
if (br.style() == Qt::LinearGradientPattern || br.style() == Qt::RadialGradientPattern || br.style() == Qt::ConicalGradientPattern) {
painter->save();
painter->translate(option.rect.x(), option.rect.y());
painter->scale(option.rect.width(), option.rect.height());
@ -544,15 +537,12 @@ void ColorDelegate::paint(QPainter *painter, const QStyleOptionViewItem &opt, co
}
QItemDelegate::paint(painter, option, index);
const QColor color = static_cast<QRgb>(QApplication::style()->styleHint(QStyle::SH_Table_GridLineColor, &option));
const QPen oldPen = painter->pen();
painter->setPen(QPen(color));
painter->drawLine(option.rect.right(), option.rect.y(),
option.rect.right(), option.rect.bottom());
painter->drawLine(option.rect.x(), option.rect.bottom(),
option.rect.right(), option.rect.bottom());
painter->drawLine(option.rect.right(), option.rect.y(), option.rect.right(), option.rect.bottom());
painter->drawLine(option.rect.x(), option.rect.bottom(), option.rect.right(), option.rect.bottom());
painter->setPen(oldPen);
}
@ -560,5 +550,4 @@ QSize ColorDelegate::sizeHint(const QStyleOptionViewItem &opt, const QModelIndex
{
return QItemDelegate::sizeHint(opt, index) + QSize(4, 4);
}
}

View File

@ -5,8 +5,8 @@
#include <c++utilities/conversion/types.h>
#include <QItemDelegate>
#include <QDialog>
#include <QItemDelegate>
#include <memory>
@ -29,15 +29,13 @@ class PaletteEditor;
* This is taken from qttools/src/designer/src/components/propertyeditor/paletteeditor.cpp.
* In contrast to the original version this version doesn't provide a preview.
*/
class QT_UTILITIES_EXPORT PaletteEditor : public QDialog
{
class QT_UTILITIES_EXPORT PaletteEditor : public QDialog {
Q_OBJECT
public:
PaletteEditor(QWidget *parent);
~PaletteEditor();
static QPalette getPalette(QWidget *parent, const QPalette &init = QPalette(),
const QPalette &parentPal = QPalette(), int *result = nullptr);
static QPalette getPalette(QWidget *parent, const QPalette &init = QPalette(), const QPalette &parentPal = QPalette(), int *result = nullptr);
QPalette palette() const;
void setPalette(const QPalette &palette);
@ -77,8 +75,7 @@ private:
/*!
* \brief The PaletteModel class is used by PaletteEditor.
*/
class QT_UTILITIES_EXPORT PaletteModel : public QAbstractTableModel
{
class QT_UTILITIES_EXPORT PaletteModel : public QAbstractTableModel {
Q_OBJECT
Q_PROPERTY(QPalette::ColorRole colorRole READ colorRole)
public:
@ -89,20 +86,24 @@ public:
QVariant data(const QModelIndex &index, int role) const;
bool setData(const QModelIndex &index, const QVariant &value, int role);
Qt::ItemFlags flags(const QModelIndex &index) const;
QVariant headerData(int section, Qt::Orientation orientation,
int role = Qt::DisplayRole) const;
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
QPalette getPalette() const;
void setPalette(const QPalette &palette, const QPalette &parentPalette);
QPalette::ColorRole colorRole() const { return QPalette::NoRole; }
void setCompute(bool on) { m_compute = on; }
QPalette::ColorRole colorRole() const
{
return QPalette::NoRole;
}
void setCompute(bool on)
{
m_compute = on;
}
Q_SIGNALS:
void paletteChanged(const QPalette &palette);
private:
QPalette::ColorGroup columnToGroup(int index) const;
int groupToColumn(QPalette::ColorGroup group) const;
@ -115,8 +116,7 @@ private:
/*!
* \brief The BrushEditor class is used by PaletteEditor.
*/
class QT_UTILITIES_EXPORT BrushEditor : public QWidget
{
class QT_UTILITIES_EXPORT BrushEditor : public QWidget {
Q_OBJECT
public:
@ -140,8 +140,7 @@ private:
/*!
* \brief The RoleEditor class is used by PaletteEditor.
*/
class QT_UTILITIES_EXPORT RoleEditor : public QWidget
{
class QT_UTILITIES_EXPORT RoleEditor : public QWidget {
Q_OBJECT
public:
explicit RoleEditor(QWidget *parent = nullptr);
@ -164,8 +163,7 @@ private:
/*!
* \brief The ColorDelegate class is used by PaletteEditor.
*/
class QT_UTILITIES_EXPORT ColorDelegate : public QItemDelegate
{
class QT_UTILITIES_EXPORT ColorDelegate : public QItemDelegate {
Q_OBJECT
public:
@ -181,7 +179,6 @@ public:
void paint(QPainter *painter, const QStyleOptionViewItem &opt, const QModelIndex &index) const;
QSize sizeHint(const QStyleOptionViewItem &opt, const QModelIndex &index) const;
};
}
#endif // WIDGETS_PALETTEEDITOR_H

View File

@ -4,18 +4,18 @@
#include "resources/config.h"
#ifdef QT_STATIC
# if defined(QT_UTILITIES_GUI_QTWIDGETS) || defined(QT_UTILITIES_GUI_QTQUICK)
# include <QtPlugin>
# ifdef Q_OS_WIN32
#if defined(QT_UTILITIES_GUI_QTWIDGETS) || defined(QT_UTILITIES_GUI_QTQUICK)
#include <QtPlugin>
#ifdef Q_OS_WIN32
Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin)
# endif
# ifdef SVG_SUPPORT
#endif
#ifdef SVG_SUPPORT
Q_IMPORT_PLUGIN(QSvgPlugin)
# endif
# ifdef SVG_ICON_SUPPORT
#endif
#ifdef SVG_ICON_SUPPORT
Q_IMPORT_PLUGIN(QSvgIconPlugin)
# endif
# endif
#endif
#endif
#endif
#endif // MISC_UTILS_IMPORT_PLUGIN_H

View File

@ -2,15 +2,15 @@
#include <c++utilities/conversion/stringconversion.h>
#include <QString>
#include <QLocale>
#include <QFont>
#include <QIcon>
#include <QLocale>
#include <QString>
#ifdef QT_UTILITIES_GUI_QTWIDGETS
# include <QApplication>
# include <QStyleFactory>
#include <QApplication>
#include <QStyleFactory>
#else
# include <QGuiApplication>
#include <QGuiApplication>
#endif
#include <initializer_list>
@ -24,45 +24,46 @@ namespace ApplicationUtilities {
/*!
* \brief Constructs new Qt config arguments.
*/
QtConfigArguments::QtConfigArguments() :
m_qtWidgetsGuiArg("qt-widgets-gui", 'g', "shows a Qt widgets based graphical user interface"),
m_qtQuickGuiArg("qt-quick-gui", 'q', "shows a Qt quick based graphical user interface"),
m_lngArg("lang", 'l', "sets the language for the Qt GUI"),
m_qmlDebuggerArg("qmljsdebugger", '\0', "enables QML debugging (see http://doc.qt.io/qt-5/qtquick-debugging.html)"),
m_styleArg("style", '\0', "sets the Qt widgets style"),
m_iconThemeArg("icon-theme", '\0', "sets the icon theme and additional theme search paths for the Qt GUI"),
m_fontArg("font", '\0', "sets the font family and size (point) for the Qt GUI"),
m_libraryPathsArg("library-paths", '\0', "sets the list of directories to search when loading libraries (all existing paths will be deleted)"),
m_platformThemeArg("platformtheme", '\0', "specifies the Qt platform theme to be used")
QtConfigArguments::QtConfigArguments()
: m_qtWidgetsGuiArg("qt-widgets-gui", 'g', "shows a Qt widgets based graphical user interface")
, m_qtQuickGuiArg("qt-quick-gui", 'q', "shows a Qt quick based graphical user interface")
, m_lngArg("lang", 'l', "sets the language for the Qt GUI")
, m_qmlDebuggerArg("qmljsdebugger", '\0', "enables QML debugging (see http://doc.qt.io/qt-5/qtquick-debugging.html)")
, m_styleArg("style", '\0', "sets the Qt widgets style")
, m_iconThemeArg("icon-theme", '\0', "sets the icon theme and additional theme search paths for the Qt GUI")
, m_fontArg("font", '\0', "sets the font family and size (point) for the Qt GUI")
, m_libraryPathsArg("library-paths", '\0', "sets the list of directories to search when loading libraries (all existing paths will be deleted)")
, m_platformThemeArg("platformtheme", '\0', "specifies the Qt platform theme to be used")
{
// language
m_lngArg.setValueNames({"language"});
m_lngArg.setValueNames({ "language" });
m_lngArg.setRequiredValueCount(1);
m_lngArg.setRequired(false);
m_lngArg.setCombinable(true);
// qml debugger (handled by Qt, just to let the parser know of it)
m_qmlDebuggerArg.setValueNames({"port:<port_from>[,port_to][,host:<ip address>][,block]"});
m_qmlDebuggerArg.setValueNames({ "port:<port_from>[,port_to][,host:<ip address>][,block]" });
m_qmlDebuggerArg.setRequiredValueCount(1);
m_qmlDebuggerArg.setCombinable(true);
// appearance
m_styleArg.setValueNames({"style name"});
m_styleArg.setValueNames({ "style name" });
m_styleArg.setRequiredValueCount(1);
m_styleArg.setCombinable(true);
m_iconThemeArg.setValueNames({"theme name", "search path 1", "search path 2"});
m_iconThemeArg.setValueNames({ "theme name", "search path 1", "search path 2" });
m_iconThemeArg.setRequiredValueCount(-1);
m_iconThemeArg.setCombinable(true);
m_fontArg.setValueNames({"name", "size"});
m_fontArg.setValueNames({ "name", "size" });
m_fontArg.setRequiredValueCount(2);
m_fontArg.setCombinable(true);
m_libraryPathsArg.setValueNames({"path 1", "path 2"});
m_libraryPathsArg.setValueNames({ "path 1", "path 2" });
m_libraryPathsArg.setRequiredValueCount(-1);
m_libraryPathsArg.setCombinable(true);
m_platformThemeArg.setRequiredValueCount(1);
m_platformThemeArg.setCombinable(true);
m_platformThemeArg.setValueNames({"qt5ct/kde/..."});
m_platformThemeArg.setValueNames({ "qt5ct/kde/..." });
m_platformThemeArg.setPreDefinedCompletionValues("qt5ct kde gnome");
m_qtWidgetsGuiArg.setSubArguments({&m_lngArg, &m_qmlDebuggerArg, &m_styleArg, &m_iconThemeArg, &m_fontArg, &m_libraryPathsArg, &m_platformThemeArg});
m_qtQuickGuiArg.setSubArguments({&m_lngArg, &m_qmlDebuggerArg, &m_iconThemeArg, &m_fontArg, &m_libraryPathsArg, &m_platformThemeArg});
m_qtWidgetsGuiArg.setSubArguments(
{ &m_lngArg, &m_qmlDebuggerArg, &m_styleArg, &m_iconThemeArg, &m_fontArg, &m_libraryPathsArg, &m_platformThemeArg });
m_qtQuickGuiArg.setSubArguments({ &m_lngArg, &m_qmlDebuggerArg, &m_iconThemeArg, &m_fontArg, &m_libraryPathsArg, &m_platformThemeArg });
m_qtWidgetsGuiArg.setDenotesOperation(true);
m_qtQuickGuiArg.setDenotesOperation(true);
#if defined QT_UTILITIES_GUI_QTWIDGETS
@ -79,30 +80,30 @@ QtConfigArguments::QtConfigArguments() :
*/
void QtConfigArguments::applySettings(bool preventApplyingDefaultFont) const
{
if(m_lngArg.isPresent()) {
if (m_lngArg.isPresent()) {
QLocale::setDefault(QLocale(QString::fromLocal8Bit(m_lngArg.values().front())));
}
if(m_styleArg.isPresent()) {
if (m_styleArg.isPresent()) {
#ifdef QT_UTILITIES_GUI_QTWIDGETS
if(QStyle *style = QStyleFactory::create(QString::fromLocal8Bit(m_styleArg.values().front()))) {
if (QStyle *style = QStyleFactory::create(QString::fromLocal8Bit(m_styleArg.values().front()))) {
QApplication::setStyle(style);
} else {
cerr << "Warning: Can not find the specified style." << endl;
}
#else
# ifdef QT_UTILITIES_GUI_QTQUICK
#ifdef QT_UTILITIES_GUI_QTQUICK
cerr << "Warning: Can not set a style for the Qt Quick GUI." << endl;
# endif
#endif
#endif
}
if(m_iconThemeArg.isPresent()) {
if (m_iconThemeArg.isPresent()) {
auto i = m_iconThemeArg.values().cbegin(), end = m_iconThemeArg.values().end();
if(i != end) {
if (i != end) {
QIcon::setThemeName(QString::fromLocal8Bit(*i));
if(++i != end) {
if (++i != end) {
QStringList searchPaths;
searchPaths.reserve(m_iconThemeArg.values().size() - 1);
for(; i != end; ++i) {
for (; i != end; ++i) {
searchPaths << QString::fromLocal8Bit(*i);
}
searchPaths << QStringLiteral(":/icons");
@ -110,14 +111,14 @@ void QtConfigArguments::applySettings(bool preventApplyingDefaultFont) const
}
}
} else {
if(qEnvironmentVariableIsSet("ICON_THEME_SEARCH_PATH")) {
if (qEnvironmentVariableIsSet("ICON_THEME_SEARCH_PATH")) {
QString path;
path.append(qgetenv("ICON_THEME_SEARCH_PATH"));
QIcon::setThemeSearchPaths(QStringList() << path << QStringLiteral(":/icons"));
} else {
QIcon::setThemeSearchPaths(QIcon::themeSearchPaths() << QStringLiteral("../share/icons") << QStringLiteral(":/icons"));
}
if(qEnvironmentVariableIsSet("ICON_THEME")) {
if (qEnvironmentVariableIsSet("ICON_THEME")) {
QString themeName;
themeName.append(qgetenv("ICON_THEME"));
QIcon::setThemeName(themeName);
@ -125,35 +126,34 @@ void QtConfigArguments::applySettings(bool preventApplyingDefaultFont) const
}
#ifdef Q_OS_WIN32
// default configuration under Windows
if(QIcon::themeName().isEmpty()) {
if (QIcon::themeName().isEmpty()) {
QIcon::setThemeName(QStringLiteral("default"));
}
#endif
if(m_fontArg.isPresent()) {
if (m_fontArg.isPresent()) {
QFont font;
font.setFamily(QString::fromLocal8Bit(m_fontArg.values().front()));
try {
font.setPointSize(stringToNumber<int>(m_fontArg.values().back()));
} catch(const ConversionException &) {
} catch (const ConversionException &) {
cerr << "Warning: The specified font size is no number and will be ignored." << endl;
}
QGuiApplication::setFont(font);
}
#ifdef Q_OS_WIN32
else if(!preventApplyingDefaultFont) {
else if (!preventApplyingDefaultFont) {
QGuiApplication::setFont(QFont(QStringLiteral("Segoe UI"), 9));
}
#else
VAR_UNUSED(preventApplyingDefaultFont)
#endif
if(m_libraryPathsArg.isPresent()) {
if (m_libraryPathsArg.isPresent()) {
QStringList libraryPaths;
libraryPaths.reserve(m_libraryPathsArg.values().size());
for(const auto &path : m_libraryPathsArg.values()) {
for (const auto &path : m_libraryPathsArg.values()) {
libraryPaths << QString::fromLocal8Bit(path);
}
QCoreApplication::setLibraryPaths(libraryPaths);
}
}
}

View File

@ -7,8 +7,7 @@
namespace ApplicationUtilities {
class QT_UTILITIES_EXPORT QtConfigArguments
{
class QT_UTILITIES_EXPORT QtConfigArguments {
public:
QtConfigArguments();
@ -62,13 +61,11 @@ inline bool QtConfigArguments::areQtGuiArgsPresent() const
{
return m_qtWidgetsGuiArg.isPresent() || m_qtQuickGuiArg.isPresent();
}
}
#endif // APPLICATION_UTILITIES_QTCONFIGARGUMENTS_H
#ifdef QT_CONFIG_ARGUMENTS
# undef QT_CONFIG_ARGUMENTS
#undef QT_CONFIG_ARGUMENTS
#endif
#define QT_CONFIG_ARGUMENTS ApplicationUtilities::QtConfigArguments

View File

@ -2,25 +2,25 @@
#include "resources/config.h"
#include <QString>
#include <QLocale>
#include <QTranslator>
#include <QLibraryInfo>
#include <QFile>
#include <QDir>
#include <QStringBuilder>
#include <QFile>
#include <QLibraryInfo>
#include <QLocale>
#include <QSettings>
#include <QString>
#include <QStringBuilder>
#include <QTranslator>
#if defined(QT_UTILITIES_GUI_QTWIDGETS)
# include <QApplication>
# include <QIcon>
# include <QFont>
# include <QStyleFactory>
#include <QApplication>
#include <QFont>
#include <QIcon>
#include <QStyleFactory>
#elif defined(QT_UTILITIES_GUI_QTQUICK)
# include <QGuiApplication>
# include <QIcon>
# include <QFont>
#include <QFont>
#include <QGuiApplication>
#include <QIcon>
#else
# include <QCoreApplication>
#include <QCoreApplication>
#endif
#include <iostream>
@ -28,11 +28,13 @@
using namespace std;
///! \cond
inline void initResources() {
inline void initResources()
{
Q_INIT_RESOURCE(qtutilsicons);
}
inline void cleanupResources() {
inline void cleanupResources()
{
Q_CLEANUP_RESOURCE(qtutilsicons);
}
///! \endcond
@ -60,7 +62,6 @@ void cleanup()
{
cleanupResources();
}
}
/*!
@ -106,21 +107,22 @@ void loadQtTranslationFile(std::initializer_list<QString> repositoryNames)
*/
void loadQtTranslationFile(initializer_list<QString> repositoryNames, const QString &localeName)
{
for(const QString &repoName : repositoryNames) {
for (const QString &repoName : repositoryNames) {
QTranslator *qtTranslator = new QTranslator;
const QString fileName(repoName % QChar('_') % localeName);
if(!additionalTranslationFilePath().isEmpty() && qtTranslator->load(fileName, additionalTranslationFilePath())) {
if (!additionalTranslationFilePath().isEmpty() && qtTranslator->load(fileName, additionalTranslationFilePath())) {
QCoreApplication::installTranslator(qtTranslator);
} else if(qtTranslator->load(fileName, QLibraryInfo::location(QLibraryInfo::TranslationsPath))) {
} else if (qtTranslator->load(fileName, QLibraryInfo::location(QLibraryInfo::TranslationsPath))) {
QCoreApplication::installTranslator(qtTranslator);
} else if(qtTranslator->load(fileName, QStringLiteral("../share/qt/translations"))) {
} else if (qtTranslator->load(fileName, QStringLiteral("../share/qt/translations"))) {
// used in Windows
QCoreApplication::installTranslator(qtTranslator);
} else if(qtTranslator->load(fileName, QStringLiteral(":/translations"))) {
} else if (qtTranslator->load(fileName, QStringLiteral(":/translations"))) {
QCoreApplication::installTranslator(qtTranslator);
} else {
delete qtTranslator;
cerr << "Unable to load translation file for Qt repository \"" << repoName.toLocal8Bit().data() << "\" and language " << localeName.toLocal8Bit().data() << "." << endl;
cerr << "Unable to load translation file for Qt repository \"" << repoName.toLocal8Bit().data() << "\" and language "
<< localeName.toLocal8Bit().data() << "." << endl;
}
}
}
@ -143,7 +145,7 @@ void loadApplicationTranslationFile(const QString &applicationName)
// load English translation files as fallback
loadApplicationTranslationFile(applicationName, QStringLiteral("en_US"));
// load translation files for current locale
if(QLocale().name() != QLatin1String("en_US")) {
if (QLocale().name() != QLatin1String("en_US")) {
loadApplicationTranslationFile(applicationName, QLocale().name());
}
}
@ -166,21 +168,22 @@ void loadApplicationTranslationFile(const QString &applicationName, const QStrin
{
QTranslator *appTranslator = new QTranslator;
const QString fileName(QStringLiteral("%1_%2").arg(applicationName, localeName));
if(!additionalTranslationFilePath().isEmpty() && appTranslator->load(fileName, additionalTranslationFilePath())) {
if (!additionalTranslationFilePath().isEmpty() && appTranslator->load(fileName, additionalTranslationFilePath())) {
QCoreApplication::installTranslator(appTranslator);
} else if(appTranslator->load(fileName, QStringLiteral("."))) {
} else if (appTranslator->load(fileName, QStringLiteral("."))) {
QCoreApplication::installTranslator(appTranslator);
} else if(appTranslator->load(fileName, QStringLiteral("./translations"))) {
} else if (appTranslator->load(fileName, QStringLiteral("./translations"))) {
QCoreApplication::installTranslator(appTranslator);
} else if(appTranslator->load(fileName, QStringLiteral(APP_INSTALL_PREFIX "/share/%1/translations").arg(applicationName))) {
} else if (appTranslator->load(fileName, QStringLiteral(APP_INSTALL_PREFIX "/share/%1/translations").arg(applicationName))) {
QCoreApplication::installTranslator(appTranslator);
} else if(appTranslator->load(fileName, QStringLiteral("../share/%1/translations").arg(applicationName))) {
} else if (appTranslator->load(fileName, QStringLiteral("../share/%1/translations").arg(applicationName))) {
QCoreApplication::installTranslator(appTranslator);
} else if(appTranslator->load(fileName, QStringLiteral(":/translations"))) {
} else if (appTranslator->load(fileName, QStringLiteral(":/translations"))) {
QCoreApplication::installTranslator(appTranslator);
} else {
delete appTranslator;
cerr << "Unable to load translation file for \"" << applicationName.toLocal8Bit().data() << "\" and the language \"" << localeName.toLocal8Bit().data() << "\"." << endl;
cerr << "Unable to load translation file for \"" << applicationName.toLocal8Bit().data() << "\" and the language \""
<< localeName.toLocal8Bit().data() << "\"." << endl;
}
}
@ -190,7 +193,7 @@ void loadApplicationTranslationFile(const QString &applicationName, const QStrin
*/
void loadApplicationTranslationFile(const std::initializer_list<QString> &applicationNames)
{
for(const QString &applicationName : applicationNames) {
for (const QString &applicationName : applicationNames) {
loadApplicationTranslationFile(applicationName);
}
}
@ -202,11 +205,10 @@ void loadApplicationTranslationFile(const std::initializer_list<QString> &applic
*/
void loadApplicationTranslationFile(const std::initializer_list<QString> &applicationNames, const QString &localeName)
{
for(const QString &applicationName : applicationNames) {
for (const QString &applicationName : applicationNames) {
loadApplicationTranslationFile(applicationName, localeName);
}
}
}
/*!
@ -241,7 +243,6 @@ bool hasCoreApp()
{
return qobject_cast<QCoreApplication *>(QCoreApplication::instance()) != nullptr;
}
}
/*!
@ -256,27 +257,27 @@ namespace ConfigFile {
QString locateConfigFile(const QString &applicationName, const QString &fileName, const QSettings *settings)
{
// check whether the file is in the current working directory
if(QFile::exists(fileName)) {
if (QFile::exists(fileName)) {
return fileName;
} else {
// check whether the file is in the settings directory used by QSettings
QString path;
if(settings) {
if (settings) {
path = QFileInfo(settings->fileName()).absoluteDir().absoluteFilePath(fileName);
if(QFile::exists(path)) {
if (QFile::exists(path)) {
return path;
}
}
// check whether there is a user created version of the file under /etc/app/
// check whether there is a user created version of the file under /etc/app/
#ifdef Q_OS_WIN32
// use relative paths on Windows
path = QStringLiteral("../etc/") % applicationName % QChar('/') % fileName;
if(QFile::exists(path)) {
if (QFile::exists(path)) {
return path;
} else {
// check whether there is the default version of the file under /usr/share/app/
path = QStringLiteral("../share/") % applicationName % QChar('/') % fileName;
if(QFile::exists(path)) {
if (QFile::exists(path)) {
return path;
} else {
return QString(); // file is not present
@ -284,12 +285,12 @@ QString locateConfigFile(const QString &applicationName, const QString &fileName
}
#else
path = QStringLiteral("/etc/") % applicationName % QChar('/') % fileName;
if(QFile::exists(path)) {
if (QFile::exists(path)) {
return path;
} else {
// check whether there is the default version of the file under /usr/share/app/
path = QStringLiteral("/usr/share/") % applicationName % QChar('/') % fileName;
if(QFile::exists(path)) {
if (QFile::exists(path)) {
return path;
} else {
return QString(); // file is not present
@ -298,5 +299,4 @@ QString locateConfigFile(const QString &applicationName, const QString &fileName
#endif
}
}
}

View File

@ -14,25 +14,24 @@ QT_FORWARD_DECLARE_CLASS(QSettings)
/*!
* \brief Sets the application meta data in the QCoreApplication singleton.
*/
#define SET_QT_APPLICATION_INFO \
QCoreApplication::setOrganizationName(QStringLiteral(APP_AUTHOR)); \
QCoreApplication::setOrganizationDomain(QStringLiteral(APP_URL)); \
QCoreApplication::setApplicationName(QStringLiteral(APP_NAME)); \
QCoreApplication::setApplicationVersion(QStringLiteral(APP_VERSION)); \
#define SET_QT_APPLICATION_INFO \
QCoreApplication::setOrganizationName(QStringLiteral(APP_AUTHOR)); \
QCoreApplication::setOrganizationDomain(QStringLiteral(APP_URL)); \
QCoreApplication::setApplicationName(QStringLiteral(APP_NAME)); \
QCoreApplication::setApplicationVersion(QStringLiteral(APP_VERSION)); \
QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps, true)
/*!
* \brief Loads translations for Qt, other dependencies and the application.
*/
#define LOAD_QT_TRANSLATIONS \
TranslationFiles::loadQtTranslationFile(QT_TRANSLATION_FILES); \
#define LOAD_QT_TRANSLATIONS \
TranslationFiles::loadQtTranslationFile(QT_TRANSLATION_FILES); \
TranslationFiles::loadApplicationTranslationFile(APP_SPECIFIC_QT_TRANSLATION_FILES)
namespace QtUtilitiesResources {
QT_UTILITIES_EXPORT void init();
QT_UTILITIES_EXPORT void cleanup();
}
namespace TranslationFiles {
@ -44,7 +43,6 @@ QT_UTILITIES_EXPORT void loadApplicationTranslationFile(const QString &applicati
QT_UTILITIES_EXPORT void loadApplicationTranslationFile(const QString &applicationName, const QString &localeName);
QT_UTILITIES_EXPORT void loadApplicationTranslationFile(const std::initializer_list<QString> &applicationNames);
QT_UTILITIES_EXPORT void loadApplicationTranslationFile(const std::initializer_list<QString> &applicationNames, const QString &localeName);
}
namespace ApplicationInstances {
@ -56,13 +54,11 @@ QT_UTILITIES_EXPORT bool hasWidgetsApp();
QT_UTILITIES_EXPORT bool hasGuiApp();
#endif
QT_UTILITIES_EXPORT bool hasCoreApp();
}
namespace ConfigFile {
QT_UTILITIES_EXPORT QString locateConfigFile(const QString &applicationName, const QString &fileName, const QSettings *settings = nullptr);
}
#endif // APPLICATION_UTILITIES_RESOURCES_H

View File

@ -11,10 +11,11 @@ namespace Dialogs {
/*!
* \brief Constructs a option category.
*/
OptionCategory::OptionCategory(QObject *parent) :
QObject(parent),
m_currentIndex(0)
{}
OptionCategory::OptionCategory(QObject *parent)
: QObject(parent)
, m_currentIndex(0)
{
}
/*!
* \brief Destroys the option category.
@ -30,8 +31,8 @@ OptionCategory::~OptionCategory()
*/
bool OptionCategory::applyAllPages()
{
for(OptionPage *page : m_pages) {
if(!page->apply()) {
for (OptionPage *page : m_pages) {
if (!page->apply()) {
return false;
}
}
@ -44,7 +45,7 @@ bool OptionCategory::applyAllPages()
*/
void OptionCategory::resetAllPages()
{
for(OptionPage *page : m_pages) {
for (OptionPage *page : m_pages) {
page->reset();
}
}
@ -54,8 +55,8 @@ void OptionCategory::resetAllPages()
*/
bool OptionCategory::matches(const QString &searchKeyWord) const
{
for(OptionPage *page : m_pages) {
if(page->matches(searchKeyWord)) {
for (OptionPage *page : m_pages) {
if (page->matches(searchKeyWord)) {
return true;
}
}
@ -89,5 +90,4 @@ void OptionCategory::assignPages(const QList<OptionPage *> pages)
* \fn OptionCategory::pagesChanged()
* \brief Emitted when the pages changed.
*/
}

View File

@ -3,16 +3,15 @@
#include "../global.h"
#include <QObject>
#include <QIcon>
#include <QList>
#include <QObject>
namespace Dialogs {
class OptionPage;
class QT_UTILITIES_EXPORT OptionCategory : public QObject
{
class QT_UTILITIES_EXPORT OptionCategory : public QObject {
Q_OBJECT
Q_PROPERTY(QString displayName READ displayName WRITE setDisplayName NOTIFY displayNameChanged)
Q_PROPERTY(QIcon icon READ icon WRITE setIcon NOTIFY iconChanged)
@ -21,7 +20,7 @@ class QT_UTILITIES_EXPORT OptionCategory : public QObject
public:
explicit OptionCategory(QObject *parent = nullptr);
~OptionCategory();
const QString &displayName() const;
void setDisplayName(const QString &displayName);
const QIcon &icon() const;
@ -33,7 +32,7 @@ public:
bool matches(const QString &searchKeyWord) const;
int currentIndex() const;
void setCurrentIndex(int currentIndex);
Q_SIGNALS:
void displayNameChanged();
void iconChanged();
@ -106,7 +105,6 @@ inline void OptionCategory::setCurrentIndex(int currentIndex)
{
m_currentIndex = currentIndex;
}
}
#endif // DIALOGS_OPTIONSCATEGORY_H

View File

@ -1,6 +1,6 @@
#include "./optioncategoryfiltermodel.h"
#include "./optioncategorymodel.h"
#include "./optioncategory.h"
#include "./optioncategorymodel.h"
namespace Dialogs {
@ -12,20 +12,20 @@ namespace Dialogs {
/*!
* \brief Constructs an option category filter model.
*/
OptionCategoryFilterModel::OptionCategoryFilterModel(QObject *parent) :
QSortFilterProxyModel(parent)
{}
OptionCategoryFilterModel::OptionCategoryFilterModel(QObject *parent)
: QSortFilterProxyModel(parent)
{
}
bool OptionCategoryFilterModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
{
if (QSortFilterProxyModel::filterAcceptsRow(sourceRow, sourceParent))
return true;
if(OptionCategoryModel *model = qobject_cast<OptionCategoryModel *>(sourceModel())) {
if(OptionCategory *category = model->category(sourceRow)) {
return true;
if (OptionCategoryModel *model = qobject_cast<OptionCategoryModel *>(sourceModel())) {
if (OptionCategory *category = model->category(sourceRow)) {
return category->matches(filterRegExp().pattern());
}
}
return false;
}
}

View File

@ -5,8 +5,7 @@
namespace Dialogs {
class OptionCategoryFilterModel : public QSortFilterProxyModel
{
class OptionCategoryFilterModel : public QSortFilterProxyModel {
Q_OBJECT
public:
explicit OptionCategoryFilterModel(QObject *parent = nullptr);
@ -14,9 +13,6 @@ public:
protected:
virtual bool filterAcceptsRow(int source_row, const QModelIndex &sourceParent) const;
};
}
#endif // DIALOGS_OPTIONCATEGORYFILTERMODEL_H

View File

@ -2,8 +2,8 @@
#include "./optioncategory.h"
#ifdef QT_UTILITIES_GUI_QTWIDGETS
# include <QApplication>
# include <QStyle>
#include <QApplication>
#include <QStyle>
#endif
namespace Dialogs {
@ -16,19 +16,20 @@ namespace Dialogs {
/*!
* \brief Constructs an option category model.
*/
OptionCategoryModel::OptionCategoryModel(QObject *parent) :
QAbstractListModel(parent)
{}
OptionCategoryModel::OptionCategoryModel(QObject *parent)
: QAbstractListModel(parent)
{
}
/*!
* \brief Constructs an option category model with the specified \a categories.
* \remarks The model takes ownership over the given categories.
*/
OptionCategoryModel::OptionCategoryModel(const QList<OptionCategory *> &categories, QObject *parent) :
QAbstractListModel(parent),
m_categories(categories)
OptionCategoryModel::OptionCategoryModel(const QList<OptionCategory *> &categories, QObject *parent)
: QAbstractListModel(parent)
, m_categories(categories)
{
for(OptionCategory *category : m_categories) {
for (OptionCategory *category : m_categories) {
category->setParent(this);
}
}
@ -37,7 +38,8 @@ OptionCategoryModel::OptionCategoryModel(const QList<OptionCategory *> &categori
* \brief Destroys the option category model.
*/
OptionCategoryModel::~OptionCategoryModel()
{}
{
}
/*!
* \brief Sets the \a categories for the model.
@ -49,7 +51,7 @@ void OptionCategoryModel::setCategories(const QList<OptionCategory *> categories
beginResetModel();
qDeleteAll(m_categories);
m_categories = categories;
for(OptionCategory *category : m_categories) {
for (OptionCategory *category : m_categories) {
category->setParent(this);
connect(category, &OptionCategory::displayNameChanged, this, &OptionCategoryModel::categoryChangedName);
connect(category, &OptionCategory::iconChanged, this, &OptionCategoryModel::categoryChangedIcon);
@ -64,23 +66,23 @@ int OptionCategoryModel::rowCount(const QModelIndex &parent) const
QVariant OptionCategoryModel::data(const QModelIndex &index, int role) const
{
if(index.isValid() && index.row() < m_categories.size()) {
if (index.isValid() && index.row() < m_categories.size()) {
switch (role) {
case Qt::DisplayRole:
return m_categories.at(index.row())->displayName();
case Qt::DecorationRole: {
const QIcon &icon = m_categories.at(index.row())->icon();
if(!icon.isNull()) {
if (!icon.isNull()) {
return icon.pixmap(
#ifdef QT_UTILITIES_GUI_QTWIDGETS
QApplication::style()->pixelMetric(QStyle::PM_LargeIconSize)
QApplication::style()->pixelMetric(QStyle::PM_LargeIconSize)
#else
QSize(32, 32)
QSize(32, 32)
#endif
);
}
);
}
}
}
}
return QVariant();
}
@ -90,9 +92,9 @@ QVariant OptionCategoryModel::data(const QModelIndex &index, int role) const
*/
void OptionCategoryModel::categoryChangedName()
{
if(OptionCategory *senderCategory = qobject_cast<OptionCategory *>(QObject::sender())) {
for(int i = 0, end = m_categories.size(); i < end; ++i) {
if(senderCategory == m_categories.at(i)) {
if (OptionCategory *senderCategory = qobject_cast<OptionCategory *>(QObject::sender())) {
for (int i = 0, end = m_categories.size(); i < end; ++i) {
if (senderCategory == m_categories.at(i)) {
QModelIndex index = this->index(i);
emit dataChanged(index, index, QVector<int>() << Qt::DisplayRole);
}
@ -105,14 +107,13 @@ void OptionCategoryModel::categoryChangedName()
*/
void OptionCategoryModel::categoryChangedIcon()
{
if(OptionCategory *senderCategory = qobject_cast<OptionCategory *>(QObject::sender())) {
for(int i = 0, end = m_categories.size(); i < end; ++i) {
if(senderCategory == m_categories.at(i)) {
if (OptionCategory *senderCategory = qobject_cast<OptionCategory *>(QObject::sender())) {
for (int i = 0, end = m_categories.size(); i < end; ++i) {
if (senderCategory == m_categories.at(i)) {
QModelIndex index = this->index(i);
emit dataChanged(index, index, QVector<int>() << Qt::DecorationRole);
}
}
}
}
}

View File

@ -3,22 +3,21 @@
#include "../global.h"
#include <QList>
#include <QAbstractListModel>
#include <QList>
namespace Dialogs {
class OptionPage;
class OptionCategory;
class QT_UTILITIES_EXPORT OptionCategoryModel : public QAbstractListModel
{
class QT_UTILITIES_EXPORT OptionCategoryModel : public QAbstractListModel {
Q_OBJECT
public:
explicit OptionCategoryModel(QObject *parent = nullptr);
explicit OptionCategoryModel(const QList<OptionCategory *> &categories, QObject *parent = nullptr);
virtual ~OptionCategoryModel();
const QList<OptionCategory *> &categories() const;
OptionCategory *category(const QModelIndex &index) const;
OptionCategory *category(int row) const;
@ -29,10 +28,9 @@ public:
private Q_SLOTS:
void categoryChangedName();
void categoryChangedIcon();
private:
QList<OptionCategory *> m_categories;
};
/*!
@ -52,9 +50,7 @@ inline const QList<OptionCategory *> &OptionCategoryModel::categories() const
*/
inline OptionCategory *OptionCategoryModel::category(const QModelIndex &index) const
{
return (index.isValid())
? category(index.row())
: nullptr;
return (index.isValid()) ? category(index.row()) : nullptr;
}
/*!
@ -66,7 +62,6 @@ inline OptionCategory *OptionCategoryModel::category(int row) const
{
return row < m_categories.size() ? m_categories.at(row) : nullptr;
}
}
#endif // DIALOGS_OPTIONCATEGORYMODEL_H

View File

@ -1,10 +1,10 @@
#include "./optionpage.h"
#include <QLabel>
#include <QCheckBox>
#include <QRadioButton>
#include <QPushButton>
#include <QGroupBox>
#include <QLabel>
#include <QPushButton>
#include <QRadioButton>
namespace Dialogs {
@ -18,17 +18,19 @@ namespace Dialogs {
/*!
* \brief Constructs a option page.
*/
OptionPage::OptionPage(QWidget *parentWindow) :
m_parentWindow(parentWindow),
m_shown(false),
m_keywordsInitialized(false)
{}
OptionPage::OptionPage(QWidget *parentWindow)
: m_parentWindow(parentWindow)
, m_shown(false)
, m_keywordsInitialized(false)
{
}
/*!
* \brief Destroys the option page.
*/
OptionPage::~OptionPage()
{}
{
}
/*!
* \brief Returns the widget for the option page.
@ -41,10 +43,10 @@ OptionPage::~OptionPage()
*/
QWidget *OptionPage::widget()
{
if(!m_widget) {
if (!m_widget) {
m_widget.reset(setupWidget()); // ensure widget has been created
}
if(!m_shown) {
if (!m_shown) {
m_shown = true;
reset(); // show current configuration if not shown yet
}
@ -57,29 +59,29 @@ QWidget *OptionPage::widget()
*/
bool OptionPage::matches(const QString &searchKeyWord)
{
if(searchKeyWord.isEmpty()) {
if (searchKeyWord.isEmpty()) {
return true;
}
if(!m_keywordsInitialized) {
if(!m_widget) {
if (!m_keywordsInitialized) {
if (!m_widget) {
m_widget.reset(setupWidget()); // ensure widget has been created
}
m_keywords << m_widget->windowTitle();
// find common subwidgets
for(const QLabel *label : m_widget->findChildren<QLabel *>())
for (const QLabel *label : m_widget->findChildren<QLabel *>())
m_keywords << label->text();
for(const QCheckBox *checkbox : m_widget->findChildren<QCheckBox *>())
for (const QCheckBox *checkbox : m_widget->findChildren<QCheckBox *>())
m_keywords << checkbox->text();
for(const QRadioButton *checkbox : m_widget->findChildren<QRadioButton *>())
for (const QRadioButton *checkbox : m_widget->findChildren<QRadioButton *>())
m_keywords << checkbox->text();
for(const QPushButton *pushButton : m_widget->findChildren<QPushButton *>())
for (const QPushButton *pushButton : m_widget->findChildren<QPushButton *>())
m_keywords << pushButton->text();
for(const QGroupBox *groupBox : m_widget->findChildren<QGroupBox *>())
for (const QGroupBox *groupBox : m_widget->findChildren<QGroupBox *>())
m_keywords << groupBox->title();
m_keywordsInitialized = true;
}
for(const QString &keyword : m_keywords)
if(keyword.contains(searchKeyWord, Qt::CaseInsensitive))
for (const QString &keyword : m_keywords)
if (keyword.contains(searchKeyWord, Qt::CaseInsensitive))
return true;
return false;
}
@ -98,5 +100,4 @@ bool OptionPage::matches(const QString &searchKeyWord)
* \fn OptionPage::setupWidget()
* \brief Creates the widget for the page. Called in the first invocation of widget().
*/
}

View File

@ -12,8 +12,7 @@ namespace Dialogs {
class SettingsDialog;
class QT_UTILITIES_EXPORT OptionPage
{
class QT_UTILITIES_EXPORT OptionPage {
friend class SettingsDialog;
public:
@ -83,9 +82,7 @@ inline QStringList &OptionPage::errors()
*
* \tparam UiClass Specifies the UI class generated by uic.
*/
template <class UiClass>
class QT_UTILITIES_EXPORT UiFileBasedOptionPage : public OptionPage
{
template <class UiClass> class QT_UTILITIES_EXPORT UiFileBasedOptionPage : public OptionPage {
public:
explicit UiFileBasedOptionPage(QWidget *parentWindow = nullptr);
~UiFileBasedOptionPage();
@ -105,25 +102,25 @@ private:
* \brief Constructs a new UI file based option page.
*/
template <class UiClass>
UiFileBasedOptionPage<UiClass>::UiFileBasedOptionPage(QWidget *parentWindow) :
OptionPage(parentWindow)
{}
UiFileBasedOptionPage<UiClass>::UiFileBasedOptionPage(QWidget *parentWindow)
: OptionPage(parentWindow)
{
}
/*!
* \brief Destroys the option page.
*/
template <class UiClass>
UiFileBasedOptionPage<UiClass>::~UiFileBasedOptionPage()
{}
template <class UiClass> UiFileBasedOptionPage<UiClass>::~UiFileBasedOptionPage()
{
}
/*!
* \brief Inflates the widget for the option page using the UI class.
*/
template <class UiClass>
QWidget *UiFileBasedOptionPage<UiClass>::setupWidget()
template <class UiClass> QWidget *UiFileBasedOptionPage<UiClass>::setupWidget()
{
QWidget *widget = new QWidget();
if(!m_ui) {
if (!m_ui) {
m_ui.reset(new UiClass);
}
m_ui->setupUi(widget);
@ -133,139 +130,140 @@ QWidget *UiFileBasedOptionPage<UiClass>::setupWidget()
/*!
* \brief Provides the derived class access to the UI class.
*/
template <class UiClass>
inline UiClass *UiFileBasedOptionPage<UiClass>::ui()
template <class UiClass> inline UiClass *UiFileBasedOptionPage<UiClass>::ui()
{
return m_ui.get();
}
}
/*!
* \brief Declares a class inheriting from Dialogs::OptionPage in a convenient way.
* \remarks Must be closed with END_DECLARE_OPTION_PAGE.
*/
#define BEGIN_DECLARE_OPTION_PAGE(SomeClass) \
typedef ::Dialogs::OptionPage SomeClass ## Base; \
class QT_UTILITIES_EXPORT SomeClass : public ::Dialogs::OptionPage \
{ \
public: \
explicit SomeClass(QWidget *parentWidget = nullptr); \
~SomeClass(); \
bool apply(); \
void reset(); \
#define BEGIN_DECLARE_OPTION_PAGE(SomeClass) \
typedef ::Dialogs::OptionPage SomeClass##Base; \
class QT_UTILITIES_EXPORT SomeClass : public ::Dialogs::OptionPage { \
public: \
explicit SomeClass(QWidget *parentWidget = nullptr); \
~SomeClass(); \
bool apply(); \
void reset(); \
\
private:
/*!
* \brief Declares a class inheriting from Dialogs::UiFileBasedOptionPage in a convenient way.
* \remarks Must be closed with END_DECLARE_OPTION_PAGE.
*/
#define BEGIN_DECLARE_UI_FILE_BASED_OPTION_PAGE_CUSTOM_CTOR(SomeClass) \
namespace Ui { \
class SomeClass; \
} \
typedef ::Dialogs::UiFileBasedOptionPage<Ui::SomeClass> SomeClass ## Base; \
class QT_UTILITIES_EXPORT SomeClass : public ::Dialogs::UiFileBasedOptionPage<Ui::SomeClass> \
{ \
public: \
~SomeClass(); \
bool apply(); \
void reset(); \
#define BEGIN_DECLARE_UI_FILE_BASED_OPTION_PAGE_CUSTOM_CTOR(SomeClass) \
namespace Ui { \
class SomeClass; \
} \
typedef ::Dialogs::UiFileBasedOptionPage<Ui::SomeClass> SomeClass##Base; \
class QT_UTILITIES_EXPORT SomeClass : public ::Dialogs::UiFileBasedOptionPage<Ui::SomeClass> { \
public: \
~SomeClass(); \
bool apply(); \
void reset(); \
\
private:
/*!
* \brief Declares a class inheriting from Dialogs::UiFileBasedOptionPage in a convenient way.
* \remarks Must be closed with END_DECLARE_OPTION_PAGE.
*/
#define BEGIN_DECLARE_UI_FILE_BASED_OPTION_PAGE(SomeClass) \
BEGIN_DECLARE_UI_FILE_BASED_OPTION_PAGE_CUSTOM_CTOR(SomeClass) \
public: \
explicit SomeClass(QWidget *parentWidget = nullptr); \
private:
#define BEGIN_DECLARE_UI_FILE_BASED_OPTION_PAGE(SomeClass) \
BEGIN_DECLARE_UI_FILE_BASED_OPTION_PAGE_CUSTOM_CTOR(SomeClass) \
public: \
explicit SomeClass(QWidget *parentWidget = nullptr); \
\
private:
/*!
* \brief Must be used after BEGIN_DECLARE_OPTION_PAGE and BEGIN_DECLARE_UI_FILE_BASED_OPTION_PAGE.
*/
#define END_DECLARE_OPTION_PAGE \
};
#define END_DECLARE_OPTION_PAGE \
} \
;
/*!
* \brief Instantiates a class declared with BEGIN_DECLARE_UI_FILE_BASED_OPTION_PAGE in a convenient way.
* \remarks Might be required when the class is used by another application.
*/
#define INSTANTIATE_UI_FILE_BASED_OPTION_PAGE(SomeClass) \
namespace Dialogs { \
template class UiFileBasedOptionPage<Ui::SomeClass>; \
#define INSTANTIATE_UI_FILE_BASED_OPTION_PAGE(SomeClass) \
namespace Dialogs { \
template class UiFileBasedOptionPage<Ui::SomeClass>; \
}
/*!
* \brief Instantiates a class declared with BEGIN_DECLARE_UI_FILE_BASED_OPTION_PAGE inside a given namespace in a convenient way.
* \remarks Might be required when the class is used by another application.
*/
#define INSTANTIATE_UI_FILE_BASED_OPTION_PAGE_NS(SomeNamespace, SomeClass) \
namespace Dialogs { \
template class UiFileBasedOptionPage<::SomeNamespace::Ui::SomeClass>; \
#define INSTANTIATE_UI_FILE_BASED_OPTION_PAGE_NS(SomeNamespace, SomeClass) \
namespace Dialogs { \
template class UiFileBasedOptionPage< ::SomeNamespace::Ui::SomeClass>; \
}
/*!
* \brief Declares external instantiation of class declared with BEGIN_DECLARE_UI_FILE_BASED_OPTION_PAGE in a convenient way.
* \remarks Might be required when the class comes from an external library.
*/
#define DECLARE_EXTERN_UI_FILE_BASED_OPTION_PAGE(SomeClass) \
namespace Dialogs { \
namespace Ui { \
class SomeClass; \
} \
extern template class UiFileBasedOptionPage<Ui::SomeClass>; \
#define DECLARE_EXTERN_UI_FILE_BASED_OPTION_PAGE(SomeClass) \
namespace Dialogs { \
namespace Ui { \
class SomeClass; \
} \
extern template class UiFileBasedOptionPage<Ui::SomeClass>; \
}
/*!
* \brief Declares external instantiation of class declared with BEGIN_DECLARE_UI_FILE_BASED_OPTION_PAGE inside a given namespace in a convenient way.
* \remarks Might be required when the class comes from an external library.
*/
#define DECLARE_EXTERN_UI_FILE_BASED_OPTION_PAGE_NS(SomeNamespace, SomeClass) \
namespace SomeNamespace { \
namespace Ui { \
class SomeClass; \
} \
} \
namespace Dialogs { \
extern template class UiFileBasedOptionPage<::SomeNamespace::Ui::SomeClass>; \
#define DECLARE_EXTERN_UI_FILE_BASED_OPTION_PAGE_NS(SomeNamespace, SomeClass) \
namespace SomeNamespace { \
namespace Ui { \
class SomeClass; \
} \
} \
namespace Dialogs { \
extern template class UiFileBasedOptionPage< ::SomeNamespace::Ui::SomeClass>; \
}
/*!
* \brief Declares the method setupWidget() in a convenient way.
* \remarks Can be used between BEGIN_DECLARE_OPTION_PAGE and END_DECLARE_OPTION_PAGE.
*/
#define DECLARE_SETUP_WIDGETS \
protected: \
QWidget *setupWidget(); \
private:
#define DECLARE_SETUP_WIDGETS \
protected: \
QWidget *setupWidget(); \
\
private:
/*!
* \brief Declares a class inheriting from Dialogs::OptionPage in a convenient way.
* \remarks Doesn't allow to declare additional class members.
*/
#define DECLARE_UI_FILE_BASED_OPTION_PAGE(SomeClass) \
BEGIN_DECLARE_UI_FILE_BASED_OPTION_PAGE(SomeClass) \
#define DECLARE_UI_FILE_BASED_OPTION_PAGE(SomeClass) \
BEGIN_DECLARE_UI_FILE_BASED_OPTION_PAGE(SomeClass) \
END_DECLARE_OPTION_PAGE
/*!
* \brief Declares a class inheriting from Dialogs::OptionPage in a convenient way.
* \remarks Doesn't allow to declare additional class members.
*/
#define DECLARE_OPTION_PAGE(SomeClass) \
BEGIN_DECLARE_OPTION_PAGE(SomeClass) \
DECLARE_SETUP_WIDGETS \
#define DECLARE_OPTION_PAGE(SomeClass) \
BEGIN_DECLARE_OPTION_PAGE(SomeClass) \
DECLARE_SETUP_WIDGETS \
END_DECLARE_OPTION_PAGE
/*!
* \brief Declares a class inheriting from Dialogs::UiFileBasedOptionPage in a convenient way.
* \remarks Doesn't allow to declare additional class members.
*/
#define DECLARE_UI_FILE_BASED_OPTION_PAGE_CUSTOM_SETUP(SomeClass) \
BEGIN_DECLARE_UI_FILE_BASED_OPTION_PAGE(SomeClass) \
DECLARE_SETUP_WIDGETS \
#define DECLARE_UI_FILE_BASED_OPTION_PAGE_CUSTOM_SETUP(SomeClass) \
BEGIN_DECLARE_UI_FILE_BASED_OPTION_PAGE(SomeClass) \
DECLARE_SETUP_WIDGETS \
END_DECLARE_OPTION_PAGE
#endif // DIALOGS_OPTIONSPAGE_H

View File

@ -1,7 +1,7 @@
#include "./qtsettings.h"
#include "./optioncategorymodel.h"
#include "./optioncategoryfiltermodel.h"
#include "./optioncategory.h"
#include "./optioncategoryfiltermodel.h"
#include "./optioncategorymodel.h"
#include "./optionpage.h"
#include "../paletteeditor/paletteeditor.h"
@ -11,18 +11,18 @@
#include "../resources/resources.h"
#include "ui_qtappearanceoptionpage.h"
#include "ui_qtlanguageoptionpage.h"
#include "ui_qtenvoptionpage.h"
#include "ui_qtlanguageoptionpage.h"
#include <memory>
#include <QStyleFactory>
#include <QFontDialog>
#include <QDir>
#include <QFileDialog>
#include <QFontDialog>
#include <QIcon>
#include <QSettings>
#include <QStringBuilder>
#include <QIcon>
#include <QDir>
#include <QStyleFactory>
#include <iostream>
@ -30,8 +30,7 @@ using namespace std;
namespace Dialogs {
struct QtSettingsData
{
struct QtSettingsData {
QtSettingsData();
QFont font;
@ -51,32 +50,35 @@ struct QtSettingsData
QString additionalIconThemeSearchPath;
};
inline QtSettingsData::QtSettingsData() :
customFont(false),
customPalette(false),
customWidgetStyle(false),
customStyleSheet(false),
iconTheme(QIcon::themeName()),
customIconTheme(false),
localeName(defaultLocale.name()),
customLocale(false)
{}
inline QtSettingsData::QtSettingsData()
: customFont(false)
, customPalette(false)
, customWidgetStyle(false)
, customStyleSheet(false)
, iconTheme(QIcon::themeName())
, customIconTheme(false)
, localeName(defaultLocale.name())
, customLocale(false)
{
}
/*!
* \brief Creates a new settings object.
* \remarks Settings are not restored automatically. Instead, some values (font, widget style, ...) are initialized
* from the current Qt configuration. These values are considered as system-default.
*/
QtSettings::QtSettings() :
m_d(new QtSettingsData())
{}
QtSettings::QtSettings()
: m_d(new QtSettingsData())
{
}
/*!
* \brief Destroys the settings object.
* \remarks Unlike QSettings not explicitely saved settings are not saved automatically.
*/
QtSettings::~QtSettings()
{}
{
}
/*!
* \brief Returns whether a custom font is set.
@ -147,35 +149,36 @@ void QtSettings::apply()
{
// read style sheet
QString styleSheet;
if(m_d->customStyleSheet && !m_d->styleSheetPath.isEmpty()) {
if (m_d->customStyleSheet && !m_d->styleSheetPath.isEmpty()) {
QFile file(m_d->styleSheetPath);
if(!file.open(QFile::ReadOnly)) {
if (!file.open(QFile::ReadOnly)) {
cerr << "Unable to open the specified stylesheet \"" << m_d->styleSheetPath.toLocal8Bit().data() << "\"." << endl;
}
styleSheet.append(file.readAll());
if(file.error() != QFile::NoError) {
if (file.error() != QFile::NoError) {
cerr << "Unable to read the specified stylesheet \"" << m_d->styleSheetPath.toLocal8Bit().data() << "\"." << endl;
}
}
// apply appearance
if(m_d->customFont) {
if (m_d->customFont) {
QGuiApplication::setFont(m_d->font);
}
if(m_d->customWidgetStyle) {
if (m_d->customWidgetStyle) {
QApplication::setStyle(m_d->widgetStyle);
}
if(!styleSheet.isEmpty()) {
if(auto *qapp = qobject_cast<QApplication *>(QApplication::instance())) {
if (!styleSheet.isEmpty()) {
if (auto *qapp = qobject_cast<QApplication *>(QApplication::instance())) {
qapp->setStyleSheet(styleSheet);
} else {
cerr << "Unable to apply the specified stylesheet \"" << m_d->styleSheetPath.toLocal8Bit().data() << "\" because no QApplication has been instantiated." << endl;
cerr << "Unable to apply the specified stylesheet \"" << m_d->styleSheetPath.toLocal8Bit().data()
<< "\" because no QApplication has been instantiated." << endl;
}
}
if(m_d->customPalette) {
if (m_d->customPalette) {
QGuiApplication::setPalette(m_d->palette);
}
if(m_d->customIconTheme) {
if (m_d->customIconTheme) {
QIcon::setThemeName(m_d->iconTheme);
}
@ -183,10 +186,10 @@ void QtSettings::apply()
QLocale::setDefault(m_d->customLocale ? m_d->localeName : m_d->defaultLocale);
// apply environment
if(m_d->additionalPluginDirectory.isEmpty()) {
if (m_d->additionalPluginDirectory.isEmpty()) {
QCoreApplication::addLibraryPath(m_d->additionalPluginDirectory);
}
if(!m_d->additionalIconThemeSearchPath.isEmpty()) {
if (!m_d->additionalIconThemeSearchPath.isEmpty()) {
QIcon::setThemeSearchPaths(QIcon::themeSearchPaths() << m_d->additionalIconThemeSearchPath);
}
}
@ -203,25 +206,24 @@ OptionCategory *QtSettings::category()
auto *category = new OptionCategory;
category->setDisplayName(QCoreApplication::translate("QtGui::QtOptionCategory", "Qt"));
category->setIcon(QIcon::fromTheme(QStringLiteral("qtcreator"), QIcon(QStringLiteral(":/qtutilities/icons/hicolor/48x48/apps/qtcreator.svg"))));
category->assignPages(QList<OptionPage *>()
<< new QtAppearanceOptionPage(*m_d)
<< new QtLanguageOptionPage(*m_d)
<< new QtEnvOptionPage(*m_d));
category->assignPages(QList<OptionPage *>() << new QtAppearanceOptionPage(*m_d) << new QtLanguageOptionPage(*m_d) << new QtEnvOptionPage(*m_d));
return category;
}
QtAppearanceOptionPage::QtAppearanceOptionPage(QtSettingsData &settings, QWidget *parentWidget) :
QtAppearanceOptionPageBase(parentWidget),
m_settings(settings),
m_fontDialog(nullptr)
{}
QtAppearanceOptionPage::QtAppearanceOptionPage(QtSettingsData &settings, QWidget *parentWidget)
: QtAppearanceOptionPageBase(parentWidget)
, m_settings(settings)
, m_fontDialog(nullptr)
{
}
QtAppearanceOptionPage::~QtAppearanceOptionPage()
{}
{
}
bool QtAppearanceOptionPage::apply()
{
if(hasBeenShown()) {
if (hasBeenShown()) {
m_settings.font = ui()->fontComboBox->font();
m_settings.customFont = !ui()->fontCheckBox->isChecked();
m_settings.widgetStyle = ui()->widgetStyleComboBox->currentText();
@ -230,7 +232,8 @@ bool QtAppearanceOptionPage::apply()
m_settings.customStyleSheet = !ui()->styleSheetCheckBox->isChecked();
m_settings.palette = ui()->paletteToolButton->palette();
m_settings.customPalette = !ui()->paletteCheckBox->isChecked();
m_settings.iconTheme = ui()->iconThemeComboBox->currentIndex() != -1 ? ui()->iconThemeComboBox->currentData().toString() : ui()->iconThemeComboBox->currentText();
m_settings.iconTheme = ui()->iconThemeComboBox->currentIndex() != -1 ? ui()->iconThemeComboBox->currentData().toString()
: ui()->iconThemeComboBox->currentText();
m_settings.customIconTheme = !ui()->iconThemeCheckBox->isChecked();
}
return true;
@ -238,17 +241,18 @@ bool QtAppearanceOptionPage::apply()
void QtAppearanceOptionPage::reset()
{
if(hasBeenShown()) {
if (hasBeenShown()) {
ui()->fontComboBox->setCurrentFont(m_settings.font);
ui()->fontCheckBox->setChecked(!m_settings.customFont);
ui()->widgetStyleComboBox->setCurrentText(m_settings.widgetStyle.isEmpty() ? (QApplication::style() ? QApplication::style()->objectName() : QString()) : m_settings.widgetStyle);
ui()->widgetStyleComboBox->setCurrentText(
m_settings.widgetStyle.isEmpty() ? (QApplication::style() ? QApplication::style()->objectName() : QString()) : m_settings.widgetStyle);
ui()->widgetStyleCheckBox->setChecked(!m_settings.customWidgetStyle);
ui()->styleSheetPathSelection->lineEdit()->setText(m_settings.styleSheetPath);
ui()->styleSheetCheckBox->setChecked(!m_settings.customStyleSheet);
ui()->paletteToolButton->setPalette(m_settings.palette);
ui()->paletteCheckBox->setChecked(!m_settings.customPalette);
int iconThemeIndex = ui()->iconThemeComboBox->findData(m_settings.iconTheme);
if(iconThemeIndex != -1) {
if (iconThemeIndex != -1) {
ui()->iconThemeComboBox->setCurrentIndex(iconThemeIndex);
} else {
ui()->iconThemeComboBox->setCurrentText(m_settings.iconTheme);
@ -270,7 +274,7 @@ QWidget *QtAppearanceOptionPage::setupWidget()
// setup font selection
QObject::connect(ui()->fontPushButton, &QPushButton::clicked, [this] {
if(!m_fontDialog) {
if (!m_fontDialog) {
m_fontDialog = new QFontDialog(this->widget());
m_fontDialog->setCurrentFont(ui()->fontComboBox->font());
QObject::connect(m_fontDialog, &QFontDialog::fontSelected, ui()->fontComboBox, &QFontComboBox::setCurrentFont);
@ -280,28 +284,27 @@ QWidget *QtAppearanceOptionPage::setupWidget()
});
// setup palette selection
QObject::connect(ui()->paletteToolButton, &QToolButton::clicked, [this] {
ui()->paletteToolButton->setPalette(PaletteEditor::getPalette(this->widget(), ui()->paletteToolButton->palette()));
});
QObject::connect(ui()->paletteToolButton, &QToolButton::clicked,
[this] { ui()->paletteToolButton->setPalette(PaletteEditor::getPalette(this->widget(), ui()->paletteToolButton->palette())); });
// setup icon theme selection
const QStringList searchPaths = QIcon::themeSearchPaths() << QStringLiteral("/usr/share/icons/");
for(const QString &searchPath : searchPaths) {
for(const QString &iconTheme : QDir(searchPath).entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name)) {
for (const QString &searchPath : searchPaths) {
for (const QString &iconTheme : QDir(searchPath).entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name)) {
const int existingItemIndex = ui()->iconThemeComboBox->findData(iconTheme);
QFile indexFile(searchPath % QChar('/') % iconTheme % QStringLiteral("/index.theme"));
QByteArray index;
if(indexFile.open(QFile::ReadOnly) && !(index = indexFile.readAll()).isEmpty()) {
if (indexFile.open(QFile::ReadOnly) && !(index = indexFile.readAll()).isEmpty()) {
const int iconThemeSection = index.indexOf("[Icon Theme]");
const int nameStart = index.indexOf("Name=", iconThemeSection != -1 ? iconThemeSection : 0);
if(nameStart != -1) {
if (nameStart != -1) {
int nameLength = index.indexOf("\n", nameStart) - nameStart - 5;
if(nameLength > 0) {
if (nameLength > 0) {
QString displayName = index.mid(nameStart + 5, nameLength);
if(displayName != iconTheme) {
if (displayName != iconTheme) {
displayName += QChar(' ') % QChar('(') % iconTheme % QChar(')');
}
if(existingItemIndex != -1) {
if (existingItemIndex != -1) {
ui()->iconThemeComboBox->setItemText(existingItemIndex, displayName);
} else {
ui()->iconThemeComboBox->addItem(displayName, iconTheme);
@ -310,7 +313,7 @@ QWidget *QtAppearanceOptionPage::setupWidget()
}
}
}
if(existingItemIndex == -1) {
if (existingItemIndex == -1) {
ui()->iconThemeComboBox->addItem(iconTheme, iconTheme);
}
}
@ -319,17 +322,19 @@ QWidget *QtAppearanceOptionPage::setupWidget()
return widget;
}
QtLanguageOptionPage::QtLanguageOptionPage(QtSettingsData &settings, QWidget *parentWidget) :
QtLanguageOptionPageBase(parentWidget),
m_settings(settings)
{}
QtLanguageOptionPage::QtLanguageOptionPage(QtSettingsData &settings, QWidget *parentWidget)
: QtLanguageOptionPageBase(parentWidget)
, m_settings(settings)
{
}
QtLanguageOptionPage::~QtLanguageOptionPage()
{}
{
}
bool QtLanguageOptionPage::apply()
{
if(hasBeenShown()) {
if (hasBeenShown()) {
m_settings.localeName = ui()->localeComboBox->currentText();
m_settings.customLocale = !ui()->localeCheckBox->isChecked();
}
@ -338,7 +343,7 @@ bool QtLanguageOptionPage::apply()
void QtLanguageOptionPage::reset()
{
if(hasBeenShown()) {
if (hasBeenShown()) {
ui()->localeComboBox->setCurrentText(m_settings.localeName);
ui()->localeCheckBox->setChecked(!m_settings.customLocale);
}
@ -351,10 +356,7 @@ QWidget *QtLanguageOptionPage::setupWidget()
// add all available locales to combo box
auto *localeComboBox = ui()->localeComboBox;
for(const QLocale &locale : QLocale::matchingLocales(
QLocale::AnyLanguage,
QLocale::AnyScript,
QLocale::AnyCountry)) {
for (const QLocale &locale : QLocale::matchingLocales(QLocale::AnyLanguage, QLocale::AnyScript, QLocale::AnyCountry)) {
localeComboBox->addItem(locale.name());
}
@ -362,27 +364,26 @@ QWidget *QtLanguageOptionPage::setupWidget()
QObject::connect(ui()->localeComboBox, &QComboBox::currentTextChanged, [languageLabel, localeComboBox] {
const QLocale selectedLocale(localeComboBox->currentText());
const QLocale currentLocale;
languageLabel->setText(QCoreApplication::translate("QtGui::QtLanguageOptionPage", "recognized by Qt as")
% QStringLiteral(" <i>")
% currentLocale.languageToString(selectedLocale.language())
% QChar(',') % QChar(' ')
% currentLocale.countryToString(selectedLocale.country())
% QStringLiteral("</i>"));
languageLabel->setText(QCoreApplication::translate("QtGui::QtLanguageOptionPage", "recognized by Qt as") % QStringLiteral(" <i>")
% currentLocale.languageToString(selectedLocale.language()) % QChar(',') % QChar(' ')
% currentLocale.countryToString(selectedLocale.country()) % QStringLiteral("</i>"));
});
return widget;
}
QtEnvOptionPage::QtEnvOptionPage(QtSettingsData &settings, QWidget *parentWidget) :
QtEnvOptionPageBase(parentWidget),
m_settings(settings)
{}
QtEnvOptionPage::QtEnvOptionPage(QtSettingsData &settings, QWidget *parentWidget)
: QtEnvOptionPageBase(parentWidget)
, m_settings(settings)
{
}
QtEnvOptionPage::~QtEnvOptionPage()
{}
{
}
bool QtEnvOptionPage::apply()
{
if(hasBeenShown()) {
if (hasBeenShown()) {
m_settings.additionalPluginDirectory = ui()->pluginPathSelection->lineEdit()->text();
m_settings.additionalIconThemeSearchPath = ui()->iconThemeSearchPathSelection->lineEdit()->text();
TranslationFiles::additionalTranslationFilePath() = ui()->translationPathSelection->lineEdit()->text();
@ -392,13 +393,12 @@ bool QtEnvOptionPage::apply()
void QtEnvOptionPage::reset()
{
if(hasBeenShown()) {
if (hasBeenShown()) {
ui()->pluginPathSelection->lineEdit()->setText(m_settings.additionalPluginDirectory);
ui()->iconThemeSearchPathSelection->lineEdit()->setText(m_settings.additionalIconThemeSearchPath);
ui()->translationPathSelection->lineEdit()->setText(TranslationFiles::additionalTranslationFilePath());
}
}
}
INSTANTIATE_UI_FILE_BASED_OPTION_PAGE(QtAppearanceOptionPage)

View File

@ -15,30 +15,32 @@ struct QtSettingsData;
BEGIN_DECLARE_UI_FILE_BASED_OPTION_PAGE_CUSTOM_CTOR(QtAppearanceOptionPage)
public:
explicit QtAppearanceOptionPage(QtSettingsData &settings, QWidget *parentWidget = nullptr);
explicit QtAppearanceOptionPage(QtSettingsData &settings, QWidget *parentWidget = nullptr);
private:
DECLARE_SETUP_WIDGETS
QtSettingsData &m_settings;
QFontDialog *m_fontDialog;
DECLARE_SETUP_WIDGETS
QtSettingsData &m_settings;
QFontDialog *m_fontDialog;
END_DECLARE_OPTION_PAGE
BEGIN_DECLARE_UI_FILE_BASED_OPTION_PAGE_CUSTOM_CTOR(QtLanguageOptionPage)
public:
explicit QtLanguageOptionPage(QtSettingsData &settings, QWidget *parentWidget = nullptr);
explicit QtLanguageOptionPage(QtSettingsData &settings, QWidget *parentWidget = nullptr);
private:
DECLARE_SETUP_WIDGETS
QtSettingsData &m_settings;
DECLARE_SETUP_WIDGETS
QtSettingsData &m_settings;
END_DECLARE_OPTION_PAGE
BEGIN_DECLARE_UI_FILE_BASED_OPTION_PAGE_CUSTOM_CTOR(QtEnvOptionPage)
public:
explicit QtEnvOptionPage(QtSettingsData &settings, QWidget *parentWidget = nullptr);
explicit QtEnvOptionPage(QtSettingsData &settings, QWidget *parentWidget = nullptr);
private:
QtSettingsData &m_settings;
QtSettingsData &m_settings;
END_DECLARE_OPTION_PAGE
class QT_UTILITIES_EXPORT QtSettings
{
class QT_UTILITIES_EXPORT QtSettings {
public:
QtSettings();
~QtSettings();
@ -53,7 +55,6 @@ public:
private:
std::unique_ptr<QtSettingsData> m_d;
};
}
DECLARE_EXTERN_UI_FILE_BASED_OPTION_PAGE(QtAppearanceOptionPage)

View File

@ -1,8 +1,8 @@
#include "./settingsdialog.h"
#include "./optioncategorymodel.h"
#include "./optioncategoryfiltermodel.h"
#include "./optioncategory.h"
#include "./optioncategoryfiltermodel.h"
#include "./optioncategorymodel.h"
#include "./optionpage.h"
#include "../misc/dialogutils.h"
@ -10,10 +10,10 @@
#include "ui_settingsdialog.h"
#include <QItemSelectionModel>
#include <QShowEvent>
#include <QScrollArea>
#include <QStringBuilder>
#include <QMessageBox>
#include <QScrollArea>
#include <QShowEvent>
#include <QStringBuilder>
namespace Dialogs {
@ -26,13 +26,13 @@ namespace Dialogs {
* \brief Constructs a settings dialog.
* \param parent Specifies the parent widget.
*/
SettingsDialog::SettingsDialog(QWidget *parent) :
QDialog(parent),
m_ui(new Ui::SettingsDialog),
m_categoryModel(new OptionCategoryModel(this)),
m_categoryFilterModel(new OptionCategoryFilterModel(this)),
m_currentCategory(nullptr),
m_tabBarAlwaysVisible(true)
SettingsDialog::SettingsDialog(QWidget *parent)
: QDialog(parent)
, m_ui(new Ui::SettingsDialog)
, m_categoryModel(new OptionCategoryModel(this))
, m_categoryFilterModel(new OptionCategoryFilterModel(this))
, m_currentCategory(nullptr)
, m_tabBarAlwaysVisible(true)
{
m_ui->setupUi(this);
makeHeading(m_ui->headingLabel);
@ -59,7 +59,8 @@ SettingsDialog::SettingsDialog(QWidget *parent) :
* \brief Destroys the settings dialog.
*/
SettingsDialog::~SettingsDialog()
{}
{
}
/*!
* \brief Sets whether the tab bar is always visible.
@ -68,7 +69,7 @@ SettingsDialog::~SettingsDialog()
void SettingsDialog::setTabBarAlwaysVisible(bool value)
{
m_tabBarAlwaysVisible = value;
if(m_currentCategory) {
if (m_currentCategory) {
m_ui->pagesTabWidget->tabBar()->setHidden(!value && m_currentCategory->pages().size() == 1);
}
}
@ -92,8 +93,8 @@ OptionCategory *SettingsDialog::category(int categoryIndex) const
*/
OptionPage *SettingsDialog::page(int categoryIndex, int pageIndex) const
{
if(OptionCategory *category = this->category(categoryIndex)) {
if(pageIndex < category->pages().length()) {
if (OptionCategory *category = this->category(categoryIndex)) {
if (pageIndex < category->pages().length()) {
return category->pages()[pageIndex];
}
}
@ -105,9 +106,9 @@ OptionPage *SettingsDialog::page(int categoryIndex, int pageIndex) const
*/
void SettingsDialog::showEvent(QShowEvent *event)
{
if(!event->spontaneous()) {
for(OptionCategory *category : m_categoryModel->categories()) {
for(OptionPage *page : category->pages()) {
if (!event->spontaneous()) {
for (OptionCategory *category : m_categoryModel->categories()) {
for (OptionPage *page : category->pages()) {
page->reset();
}
}
@ -129,11 +130,11 @@ void SettingsDialog::currentCategoryChanged(const QModelIndex &index)
*/
void SettingsDialog::showCategory(OptionCategory *category)
{
if(m_currentCategory) {
if (m_currentCategory) {
m_currentCategory->setCurrentIndex(m_ui->pagesTabWidget->currentIndex());
}
if(category) {
if(m_currentCategory != category) {
if (category) {
if (m_currentCategory != category) {
m_currentCategory = category;
m_ui->headingLabel->setText(category->displayName());
}
@ -156,7 +157,7 @@ void SettingsDialog::setSingleCategory(OptionCategory *singleCategory)
m_ui->filterLineEdit->setHidden(hasSingleCategory);
m_ui->categoriesListView->setHidden(hasSingleCategory);
m_ui->headingLabel->setHidden(hasSingleCategory);
if(hasSingleCategory) {
if (hasSingleCategory) {
m_ui->filterLineEdit->clear();
categoryModel()->setCategories(QList<OptionCategory *>() << singleCategory);
showCategory(singleCategory);
@ -168,14 +169,14 @@ void SettingsDialog::setSingleCategory(OptionCategory *singleCategory)
*/
void SettingsDialog::updateTabWidget()
{
if(m_currentCategory) {
if (m_currentCategory) {
m_ui->pagesTabWidget->setUpdatesEnabled(false);
const QString searchKeyWord = m_ui->filterLineEdit->text();
int index = 0, pageIndex = 0;
for(OptionPage *page : m_currentCategory->pages()) {
if(page->matches(searchKeyWord)) {
for (OptionPage *page : m_currentCategory->pages()) {
if (page->matches(searchKeyWord)) {
QScrollArea *scrollArea;
if(index < m_ui->pagesTabWidget->count()) {
if (index < m_ui->pagesTabWidget->count()) {
scrollArea = qobject_cast<QScrollArea *>(m_ui->pagesTabWidget->widget(index));
scrollArea->takeWidget();
m_ui->pagesTabWidget->setTabText(index, page->widget()->windowTitle());
@ -189,18 +190,18 @@ void SettingsDialog::updateTabWidget()
m_ui->pagesTabWidget->addTab(scrollArea, page->widget()->windowTitle());
m_ui->pagesTabWidget->setTabIcon(index, page->widget()->windowIcon());
}
if(page->widget()->layout()) {
if (page->widget()->layout()) {
page->widget()->layout()->setAlignment(Qt::AlignTop | Qt::AlignLeft);
}
scrollArea->setWidget(page->widget());
++index;
}
if(pageIndex == m_currentCategory->currentIndex()) {
if (pageIndex == m_currentCategory->currentIndex()) {
m_ui->pagesTabWidget->setCurrentIndex(pageIndex);
}
++pageIndex;
}
while(index < m_ui->pagesTabWidget->count()) {
while (index < m_ui->pagesTabWidget->count()) {
QScrollArea *scrollArea = qobject_cast<QScrollArea *>(m_ui->pagesTabWidget->widget(index));
scrollArea->takeWidget();
m_ui->pagesTabWidget->removeTab(index);
@ -219,37 +220,27 @@ void SettingsDialog::updateTabWidget()
bool SettingsDialog::apply()
{
QString errorMessage;
for(OptionCategory *category : m_categoryModel->categories()) {
for(OptionPage *page : category->pages()) {
if(!page->apply()) {
if(errorMessage.isEmpty()) {
for (OptionCategory *category : m_categoryModel->categories()) {
for (OptionPage *page : category->pages()) {
if (!page->apply()) {
if (errorMessage.isEmpty()) {
errorMessage = tr("<p><b>Errors occured when applying changes:</b></p><ul>");
}
QStringList &errors = const_cast<OptionPage *>(page)->errors();
if(errors.isEmpty()) {
errorMessage.append(QStringLiteral("<li><i>")
% category->displayName()
% QLatin1Char('/')
% page->widget()->windowTitle()
% QStringLiteral("</i>: ")
% tr("unknonw error")
% QStringLiteral("</li>"));
if (errors.isEmpty()) {
errorMessage.append(QStringLiteral("<li><i>") % category->displayName() % QLatin1Char('/') % page->widget()->windowTitle()
% QStringLiteral("</i>: ") % tr("unknonw error") % QStringLiteral("</li>"));
} else {
for(const QString &error : errors) {
errorMessage.append(QStringLiteral("<li><i>")
% category->displayName()
% QLatin1Char('/')
% page->widget()->windowTitle()
% QStringLiteral("</i>: ")
% error
% QStringLiteral("</li>"));
for (const QString &error : errors) {
errorMessage.append(QStringLiteral("<li><i>") % category->displayName() % QLatin1Char('/') % page->widget()->windowTitle()
% QStringLiteral("</i>: ") % error % QStringLiteral("</li>"));
}
errors.clear();
}
}
}
}
if(!errorMessage.isEmpty()) {
if (!errorMessage.isEmpty()) {
errorMessage.append(QStringLiteral("</ul>"));
QMessageBox::warning(this, windowTitle(), errorMessage);
}
@ -262,10 +253,9 @@ bool SettingsDialog::apply()
*/
void SettingsDialog::reset()
{
for(OptionCategory *category : m_categoryModel->categories()) {
for (OptionCategory *category : m_categoryModel->categories()) {
category->resetAllPages();
}
emit resetted();
}
}

View File

@ -18,11 +18,10 @@ namespace Ui {
class SettingsDialog;
}
class QT_UTILITIES_EXPORT SettingsDialog : public QDialog
{
class QT_UTILITIES_EXPORT SettingsDialog : public QDialog {
Q_OBJECT
Q_PROPERTY(bool tabBarAlwaysVisible READ isTabBarAlwaysVisible WRITE setTabBarAlwaysVisible)
public:
explicit SettingsDialog(QWidget *parent = nullptr);
~SettingsDialog();
@ -75,7 +74,6 @@ inline OptionCategoryModel *SettingsDialog::categoryModel()
{
return m_categoryModel;
}
}
#endif // DIALOGS_SETTINGSDIALOG_H

View File

@ -39,12 +39,12 @@
<translation></translation>
</message>
<message>
<location filename="../aboutdialog/aboutdialog.cpp" line="48"/>
<location filename="../aboutdialog/aboutdialog.cpp" line="49"/>
<source>developed by %1</source>
<translation>entwickelt von %1</translation>
</message>
<message>
<location filename="../aboutdialog/aboutdialog.cpp" line="51"/>
<location filename="../aboutdialog/aboutdialog.cpp" line="52"/>
<source>For updates and bug reports visit the &lt;a href=&quot;%1&quot; style=&quot;text-decoration: underline; color: palette(link);&quot;&gt;project website&lt;/a&gt;.</source>
<translation>Für Aktualisierung und Melden von Fehlern besuche die &lt;a href=&quot;%1&quot; style=&quot;text-decoration: underline; color: palette(link);&quot;&gt;Webseite des Projekts&lt;/a&gt;.</translation>
</message>
@ -54,8 +54,8 @@
<message>
<location filename="../enterpassworddialog/enterpassworddialog.ui" line="12"/>
<location filename="../enterpassworddialog/enterpassworddialog.ui" line="51"/>
<location filename="../enterpassworddialog/enterpassworddialog.cpp" line="181"/>
<location filename="../enterpassworddialog/enterpassworddialog.cpp" line="196"/>
<location filename="../enterpassworddialog/enterpassworddialog.cpp" line="180"/>
<location filename="../enterpassworddialog/enterpassworddialog.cpp" line="195"/>
<source>Enter the password</source>
<translation>Passwort eingeben</translation>
</message>
@ -100,28 +100,28 @@
<translation>Bestätigen</translation>
</message>
<message>
<location filename="../enterpassworddialog/enterpassworddialog.cpp" line="181"/>
<location filename="../enterpassworddialog/enterpassworddialog.cpp" line="196"/>
<location filename="../enterpassworddialog/enterpassworddialog.cpp" line="180"/>
<location filename="../enterpassworddialog/enterpassworddialog.cpp" line="195"/>
<source>Enter the new password</source>
<translation>Neues Passwort festlegen</translation>
</message>
<message>
<location filename="../enterpassworddialog/enterpassworddialog.cpp" line="281"/>
<location filename="../enterpassworddialog/enterpassworddialog.cpp" line="277"/>
<source>You didn&apos;t enter a user name.</source>
<translation>Es wurde kein Benutzername eingegeben.</translation>
</message>
<message>
<location filename="../enterpassworddialog/enterpassworddialog.cpp" line="283"/>
<location filename="../enterpassworddialog/enterpassworddialog.cpp" line="279"/>
<source>You didn&apos;t enter a password.</source>
<translation>Es wurde kein Passwort eingegeben.</translation>
</message>
<message>
<location filename="../enterpassworddialog/enterpassworddialog.cpp" line="287"/>
<location filename="../enterpassworddialog/enterpassworddialog.cpp" line="283"/>
<source>You have to enter the new password twice to ensure you enterd it correct.</source>
<translation>Um sicher zu stellen, dass das neue Passwort richtig eingegeben wurde, muss es zweimal eingegeben werden.</translation>
</message>
<message>
<location filename="../enterpassworddialog/enterpassworddialog.cpp" line="289"/>
<location filename="../enterpassworddialog/enterpassworddialog.cpp" line="285"/>
<source>You mistyped the password.</source>
<translation>Erstes und zweites Passwort stimmen nicht überein.</translation>
</message>
@ -157,22 +157,22 @@
<context>
<name>Dialogs::PaletteModel</name>
<message>
<location filename="../paletteeditor/paletteeditor.cpp" line="324"/>
<location filename="../paletteeditor/paletteeditor.cpp" line="322"/>
<source>Color Role</source>
<translation>Farbrolle</translation>
</message>
<message>
<location filename="../paletteeditor/paletteeditor.cpp" line="326"/>
<location filename="../paletteeditor/paletteeditor.cpp" line="324"/>
<source>Active</source>
<translation>Aktiv</translation>
</message>
<message>
<location filename="../paletteeditor/paletteeditor.cpp" line="328"/>
<location filename="../paletteeditor/paletteeditor.cpp" line="326"/>
<source>Inactive</source>
<translation>Inaktiv</translation>
</message>
<message>
<location filename="../paletteeditor/paletteeditor.cpp" line="330"/>
<location filename="../paletteeditor/paletteeditor.cpp" line="328"/>
<source>Disabled</source>
<translation>Deaktiviert</translation>
</message>
@ -292,7 +292,7 @@ Außerdem werden sie vielleicht vom QPA plugin überschrieben und funktionieren
</message>
<message>
<location filename="../settingsdialog/settingsdialog.ui" line="53"/>
<location filename="../settingsdialog/settingsdialog.cpp" line="142"/>
<location filename="../settingsdialog/settingsdialog.cpp" line="143"/>
<source>No category selected</source>
<translation>Keine Kategorie gewählt</translation>
</message>
@ -317,12 +317,12 @@ Außerdem werden sie vielleicht vom QPA plugin überschrieben und funktionieren
<translation></translation>
</message>
<message>
<location filename="../settingsdialog/settingsdialog.cpp" line="226"/>
<location filename="../settingsdialog/settingsdialog.cpp" line="227"/>
<source>&lt;p&gt;&lt;b&gt;Errors occured when applying changes:&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;</source>
<translation>&lt;p&gt;&lt;b&gt;Beim Anwenden der Einstellungen sind Fehler aufgetreten:&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;</translation>
</message>
<message>
<location filename="../settingsdialog/settingsdialog.cpp" line="235"/>
<location filename="../settingsdialog/settingsdialog.cpp" line="232"/>
<source>unknonw error</source>
<translation>unbekannter Fehler</translation>
</message>
@ -363,7 +363,7 @@ Außerdem werden sie vielleicht vom QPA plugin überschrieben und funktionieren
<context>
<name>QObject</name>
<message>
<location filename="../widgets/buttonoverlay.cpp" line="74"/>
<location filename="../widgets/buttonoverlay.cpp" line="78"/>
<source>Clear</source>
<translation>Text löschen</translation>
</message>
@ -371,7 +371,7 @@ Außerdem werden sie vielleicht vom QPA plugin überschrieben und funktionieren
<context>
<name>QtGui::QtLanguageOptionPage</name>
<message>
<location filename="../settingsdialog/qtsettings.cpp" line="365"/>
<location filename="../settingsdialog/qtsettings.cpp" line="367"/>
<source>recognized by Qt as</source>
<translation>von Qt erkannt als</translation>
</message>
@ -379,7 +379,7 @@ Außerdem werden sie vielleicht vom QPA plugin überschrieben und funktionieren
<context>
<name>QtGui::QtOptionCategory</name>
<message>
<location filename="../settingsdialog/qtsettings.cpp" line="204"/>
<location filename="../settingsdialog/qtsettings.cpp" line="207"/>
<source>Qt</source>
<translation></translation>
</message>
@ -397,12 +397,12 @@ Außerdem werden sie vielleicht vom QPA plugin überschrieben und funktionieren
<translation></translation>
</message>
<message>
<location filename="../misc/dialogutils.cpp" line="37"/>
<location filename="../misc/dialogutils.cpp" line="38"/>
<source>*Unsaved - %1</source>
<translation>*Nicht gespeichert - %1</translation>
</message>
<message>
<location filename="../misc/dialogutils.cpp" line="40"/>
<location filename="../misc/dialogutils.cpp" line="41"/>
<source>*%1 - %2 - %3</source>
<translation></translation>
</message>
@ -416,18 +416,18 @@ Außerdem werden sie vielleicht vom QPA plugin überschrieben und funktionieren
<translation>Wählen ...</translation>
</message>
<message>
<location filename="../widgets/pathselection.cpp" line="78"/>
<location filename="../widgets/pathselection.cpp" line="79"/>
<source>Open</source>
<translation>Öffnen</translation>
</message>
<message>
<location filename="../widgets/pathselection.cpp" line="80"/>
<location filename="../widgets/pathselection.cpp" line="82"/>
<source>Explore</source>
<translation>Im Dateibrowser öffnen</translation>
</message>
<message>
<location filename="../widgets/pathselection.cpp" line="116"/>
<location filename="../widgets/pathselection.cpp" line="118"/>
<location filename="../widgets/pathselection.cpp" line="120"/>
<source>Select path</source>
<translation>Pfad auswählen</translation>
</message>

View File

@ -34,12 +34,12 @@
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../aboutdialog/aboutdialog.cpp" line="48"/>
<location filename="../aboutdialog/aboutdialog.cpp" line="49"/>
<source>developed by %1</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../aboutdialog/aboutdialog.cpp" line="51"/>
<location filename="../aboutdialog/aboutdialog.cpp" line="52"/>
<source>For updates and bug reports visit the &lt;a href=&quot;%1&quot; style=&quot;text-decoration: underline; color: palette(link);&quot;&gt;project website&lt;/a&gt;.</source>
<translation type="unfinished"></translation>
</message>
@ -49,8 +49,8 @@
<message>
<location filename="../enterpassworddialog/enterpassworddialog.ui" line="12"/>
<location filename="../enterpassworddialog/enterpassworddialog.ui" line="51"/>
<location filename="../enterpassworddialog/enterpassworddialog.cpp" line="181"/>
<location filename="../enterpassworddialog/enterpassworddialog.cpp" line="196"/>
<location filename="../enterpassworddialog/enterpassworddialog.cpp" line="180"/>
<location filename="../enterpassworddialog/enterpassworddialog.cpp" line="195"/>
<source>Enter the password</source>
<translation type="unfinished"></translation>
</message>
@ -95,28 +95,28 @@
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../enterpassworddialog/enterpassworddialog.cpp" line="181"/>
<location filename="../enterpassworddialog/enterpassworddialog.cpp" line="196"/>
<location filename="../enterpassworddialog/enterpassworddialog.cpp" line="180"/>
<location filename="../enterpassworddialog/enterpassworddialog.cpp" line="195"/>
<source>Enter the new password</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../enterpassworddialog/enterpassworddialog.cpp" line="281"/>
<location filename="../enterpassworddialog/enterpassworddialog.cpp" line="277"/>
<source>You didn&apos;t enter a user name.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../enterpassworddialog/enterpassworddialog.cpp" line="283"/>
<location filename="../enterpassworddialog/enterpassworddialog.cpp" line="279"/>
<source>You didn&apos;t enter a password.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../enterpassworddialog/enterpassworddialog.cpp" line="287"/>
<location filename="../enterpassworddialog/enterpassworddialog.cpp" line="283"/>
<source>You have to enter the new password twice to ensure you enterd it correct.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../enterpassworddialog/enterpassworddialog.cpp" line="289"/>
<location filename="../enterpassworddialog/enterpassworddialog.cpp" line="285"/>
<source>You mistyped the password.</source>
<translation type="unfinished"></translation>
</message>
@ -152,22 +152,22 @@
<context>
<name>Dialogs::PaletteModel</name>
<message>
<location filename="../paletteeditor/paletteeditor.cpp" line="324"/>
<location filename="../paletteeditor/paletteeditor.cpp" line="322"/>
<source>Color Role</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../paletteeditor/paletteeditor.cpp" line="326"/>
<location filename="../paletteeditor/paletteeditor.cpp" line="324"/>
<source>Active</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../paletteeditor/paletteeditor.cpp" line="328"/>
<location filename="../paletteeditor/paletteeditor.cpp" line="326"/>
<source>Inactive</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../paletteeditor/paletteeditor.cpp" line="330"/>
<location filename="../paletteeditor/paletteeditor.cpp" line="328"/>
<source>Disabled</source>
<translation type="unfinished"></translation>
</message>
@ -286,7 +286,7 @@ These settings might be overwritten by your Qt 5 platfrom integration plugin and
</message>
<message>
<location filename="../settingsdialog/settingsdialog.ui" line="53"/>
<location filename="../settingsdialog/settingsdialog.cpp" line="142"/>
<location filename="../settingsdialog/settingsdialog.cpp" line="143"/>
<source>No category selected</source>
<translation type="unfinished"></translation>
</message>
@ -311,12 +311,12 @@ These settings might be overwritten by your Qt 5 platfrom integration plugin and
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../settingsdialog/settingsdialog.cpp" line="226"/>
<location filename="../settingsdialog/settingsdialog.cpp" line="227"/>
<source>&lt;p&gt;&lt;b&gt;Errors occured when applying changes:&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../settingsdialog/settingsdialog.cpp" line="235"/>
<location filename="../settingsdialog/settingsdialog.cpp" line="232"/>
<source>unknonw error</source>
<translation type="unfinished"></translation>
</message>
@ -357,7 +357,7 @@ These settings might be overwritten by your Qt 5 platfrom integration plugin and
<context>
<name>QObject</name>
<message>
<location filename="../widgets/buttonoverlay.cpp" line="74"/>
<location filename="../widgets/buttonoverlay.cpp" line="78"/>
<source>Clear</source>
<translation type="unfinished"></translation>
</message>
@ -365,7 +365,7 @@ These settings might be overwritten by your Qt 5 platfrom integration plugin and
<context>
<name>QtGui::QtLanguageOptionPage</name>
<message>
<location filename="../settingsdialog/qtsettings.cpp" line="365"/>
<location filename="../settingsdialog/qtsettings.cpp" line="367"/>
<source>recognized by Qt as</source>
<translation type="unfinished"></translation>
</message>
@ -373,7 +373,7 @@ These settings might be overwritten by your Qt 5 platfrom integration plugin and
<context>
<name>QtGui::QtOptionCategory</name>
<message>
<location filename="../settingsdialog/qtsettings.cpp" line="204"/>
<location filename="../settingsdialog/qtsettings.cpp" line="207"/>
<source>Qt</source>
<translation type="unfinished"></translation>
</message>
@ -391,12 +391,12 @@ These settings might be overwritten by your Qt 5 platfrom integration plugin and
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../misc/dialogutils.cpp" line="37"/>
<location filename="../misc/dialogutils.cpp" line="38"/>
<source>*Unsaved - %1</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../misc/dialogutils.cpp" line="40"/>
<location filename="../misc/dialogutils.cpp" line="41"/>
<source>*%1 - %2 - %3</source>
<translation type="unfinished"></translation>
</message>
@ -410,18 +410,18 @@ These settings might be overwritten by your Qt 5 platfrom integration plugin and
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../widgets/pathselection.cpp" line="78"/>
<location filename="../widgets/pathselection.cpp" line="79"/>
<source>Open</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../widgets/pathselection.cpp" line="80"/>
<location filename="../widgets/pathselection.cpp" line="82"/>
<source>Explore</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../widgets/pathselection.cpp" line="116"/>
<location filename="../widgets/pathselection.cpp" line="118"/>
<location filename="../widgets/pathselection.cpp" line="120"/>
<source>Select path</source>
<translation type="unfinished"></translation>
</message>

View File

@ -1,12 +1,12 @@
#include "./buttonoverlay.h"
#include "./iconbutton.h"
#include <QWidget>
#include <QCursor>
#include <QHBoxLayout>
#include <QStyle>
#include <QStyleOption>
#include <QToolTip>
#include <QCursor>
#include <QWidget>
#include <functional>
@ -31,12 +31,12 @@ namespace Widgets {
* \brief Constructs a button overlay for the specified \a widget.
* \param widget Specifies the widget to display the buttons on.
*/
ButtonOverlay::ButtonOverlay(QWidget *widget) :
m_widget(widget),
m_buttonWidget(new QWidget(widget)),
m_buttonLayout(new QHBoxLayout(m_buttonWidget)),
m_clearButton(nullptr),
m_infoButton(nullptr)
ButtonOverlay::ButtonOverlay(QWidget *widget)
: m_widget(widget)
, m_buttonWidget(new QWidget(widget))
, m_buttonLayout(new QHBoxLayout(m_buttonWidget))
, m_clearButton(nullptr)
, m_infoButton(nullptr)
{
// setup button widget and layout
const QMargins margins = widget->contentsMargins();
@ -44,7 +44,8 @@ ButtonOverlay::ButtonOverlay(QWidget *widget) :
opt.initFrom(m_widget);
const int frameWidth = widget->style()->pixelMetric(QStyle::PM_DefaultFrameWidth, &opt, m_widget);
const int pad = 2;
m_buttonLayout->setContentsMargins(margins.left() + frameWidth + pad, margins.top() + frameWidth, margins.right() + frameWidth + pad, margins.bottom() + frameWidth);
m_buttonLayout->setContentsMargins(
margins.left() + frameWidth + pad, margins.top() + frameWidth, margins.right() + frameWidth + pad, margins.bottom() + frameWidth);
m_buttonLayout->setAlignment(Qt::AlignCenter | Qt::AlignRight);
widget->setLayout(m_buttonLayout);
}
@ -53,23 +54,26 @@ ButtonOverlay::ButtonOverlay(QWidget *widget) :
* \brief Destroys the button overlay.
*/
ButtonOverlay::~ButtonOverlay()
{}
{
}
/*!
* \brief Sets whether the clear button is enabled.
*/
void ButtonOverlay::setClearButtonEnabled(bool enabled)
{
if(isClearButtonEnabled() && !enabled) {
if (isClearButtonEnabled() && !enabled) {
// disable clear button
m_buttonLayout->removeWidget(m_clearButton);
delete m_clearButton;
m_clearButton = nullptr;
} else if(!isClearButtonEnabled() && enabled) {
} else if (!isClearButtonEnabled() && enabled) {
// enable clear button
m_clearButton = new IconButton;
m_clearButton->setHidden(isCleared());
m_clearButton->setPixmap(/*QIcon::fromTheme(QStringLiteral("edit-clear"), */QIcon(QStringLiteral(":/qtutilities/icons/hicolor/48x48/actions/edit-clear.png")/*)*/).pixmap(16));
m_clearButton->setPixmap(/*QIcon::fromTheme(QStringLiteral("edit-clear"), */ QIcon(
QStringLiteral(":/qtutilities/icons/hicolor/48x48/actions/edit-clear.png") /*)*/)
.pixmap(16));
m_clearButton->setGeometry(0, 0, 16, 16);
m_clearButton->setToolTip(QObject::tr("Clear"));
QObject::connect(m_clearButton, &IconButton::clicked, std::bind(&ButtonOverlay::handleClearButtonClicked, this));
@ -86,11 +90,11 @@ void ButtonOverlay::setClearButtonEnabled(bool enabled)
*/
void ButtonOverlay::enableInfoButton(const QPixmap &pixmap, const QString &infoText)
{
if(!m_infoButton) {
if (!m_infoButton) {
m_infoButton = new IconButton;
m_infoButton->setGeometry(0, 0, 16, 16);
QObject::connect(m_infoButton, &IconButton::clicked, std::bind(&ButtonOverlay::showInfo, this));
if(m_clearButton) {
if (m_clearButton) {
m_buttonLayout->insertWidget(m_buttonLayout->count() - 2, m_infoButton);
} else {
m_buttonLayout->addWidget(m_infoButton);
@ -106,7 +110,7 @@ void ButtonOverlay::enableInfoButton(const QPixmap &pixmap, const QString &infoT
*/
void ButtonOverlay::disableInfoButton()
{
if(m_infoButton) {
if (m_infoButton) {
m_buttonLayout->removeWidget(m_infoButton);
delete m_infoButton;
m_infoButton = nullptr;
@ -150,7 +154,7 @@ void ButtonOverlay::removeCustomButton(QWidget *button)
*/
void ButtonOverlay::updateClearButtonVisibility(bool visible)
{
if(m_clearButton) {
if (m_clearButton) {
m_clearButton->setVisible(visible);
}
}
@ -161,7 +165,8 @@ void ButtonOverlay::updateClearButtonVisibility(bool visible)
* This method is meant to be implemented when subclassing.
*/
void ButtonOverlay::handleClearButtonClicked()
{}
{
}
/*!
* \brief Returns whether the related widget is cleared.
@ -180,9 +185,8 @@ bool ButtonOverlay::isCleared() const
*/
void ButtonOverlay::showInfo()
{
if(m_infoButton) {
if (m_infoButton) {
QToolTip::showText(QCursor::pos(), m_infoButton->toolTip(), m_infoButton);
}
}
}

View File

@ -14,8 +14,7 @@ namespace Widgets {
class IconButton;
class QT_UTILITIES_EXPORT ButtonOverlay
{
class QT_UTILITIES_EXPORT ButtonOverlay {
public:
explicit ButtonOverlay(QWidget *widget);
virtual ~ButtonOverlay();
@ -35,7 +34,7 @@ protected:
void updateClearButtonVisibility(bool visible);
virtual void handleClearButtonClicked();
private:
private:
void showInfo();
QWidget *m_widget;
@ -68,7 +67,6 @@ inline bool ButtonOverlay::isInfoButtonEnabled() const
{
return m_infoButton != nullptr;
}
}
#endif // WIDGETS_BUTTONOVERLAY_H

View File

@ -14,9 +14,9 @@ namespace Widgets {
/*!
* \brief Constructs a clear combo box.
*/
ClearComboBox::ClearComboBox(QWidget *parent) :
QComboBox(parent),
ButtonOverlay(this)
ClearComboBox::ClearComboBox(QWidget *parent)
: QComboBox(parent)
, ButtonOverlay(this)
{
const QMargins margins = contentsMargins();
QStyleOptionComboBox opt;
@ -24,7 +24,8 @@ ClearComboBox::ClearComboBox(QWidget *parent) :
const int frameWidth = style()->pixelMetric(QStyle::PM_ComboBoxFrameWidth, &opt, this);
const int pad = 2;
const int buttonWidth = style()->subControlRect(QStyle::CC_ComboBox, &opt, QStyle::SC_ComboBoxArrow, this).width();
buttonLayout()->setContentsMargins(margins.left() + frameWidth + pad, margins.top() + frameWidth, margins.right() + frameWidth + pad + buttonWidth, margins.bottom() + frameWidth);
buttonLayout()->setContentsMargins(margins.left() + frameWidth + pad, margins.top() + frameWidth,
margins.right() + frameWidth + pad + buttonWidth, margins.bottom() + frameWidth);
setClearButtonEnabled(isEditable());
connect(this, &ClearComboBox::currentTextChanged, this, &ClearComboBox::handleTextChanged);
}
@ -33,7 +34,8 @@ ClearComboBox::ClearComboBox(QWidget *parent) :
* \brief Destroys the clear combo box.
*/
ClearComboBox::~ClearComboBox()
{}
{
}
/*!
* \brief Updates the visibility of the clear button.
@ -52,5 +54,4 @@ bool ClearComboBox::isCleared() const
{
return currentText().isEmpty();
}
}

View File

@ -7,18 +7,16 @@
namespace Widgets {
class QT_UTILITIES_EXPORT ClearComboBox : public QComboBox, public ButtonOverlay
{
class QT_UTILITIES_EXPORT ClearComboBox : public QComboBox, public ButtonOverlay {
Q_OBJECT
public:
explicit ClearComboBox(QWidget *parent = nullptr);
~ClearComboBox();
bool isCleared() const;
private Q_SLOTS:
void handleTextChanged(const QString &text);
void handleClearButtonClicked();
};
} // namespace Widgets

View File

@ -10,9 +10,9 @@ namespace Widgets {
/*!
* \brief Constructs a clear line edit.
*/
ClearLineEdit::ClearLineEdit(QWidget *parent) :
QLineEdit(parent),
ButtonOverlay(this)
ClearLineEdit::ClearLineEdit(QWidget *parent)
: QLineEdit(parent)
, ButtonOverlay(this)
{
ButtonOverlay::setClearButtonEnabled(true);
connect(this, &ClearLineEdit::textChanged, this, &ClearLineEdit::handleTextChanged);
@ -22,7 +22,8 @@ ClearLineEdit::ClearLineEdit(QWidget *parent) :
* \brief Destroys the clear combo box.
*/
ClearLineEdit::~ClearLineEdit()
{}
{
}
/*!
* \brief Updates the visibility of the clear button.
@ -41,5 +42,4 @@ bool ClearLineEdit::isCleared() const
{
return text().isEmpty();
}
}

View File

@ -11,19 +11,17 @@ namespace Widgets {
class IconButton;
class QT_UTILITIES_EXPORT ClearLineEdit : public QLineEdit, public ButtonOverlay
{
class QT_UTILITIES_EXPORT ClearLineEdit : public QLineEdit, public ButtonOverlay {
Q_OBJECT
public:
explicit ClearLineEdit(QWidget *parent = nullptr);
~ClearLineEdit();
bool isCleared() const;
private Q_SLOTS:
void handleTextChanged(const QString &text);
void handleClearButtonClicked();
};
}
#endif // WIDGETS_CLEARLINEEDIT_H

View File

@ -15,9 +15,9 @@ namespace Widgets {
/*!
* \brief Constructs a clear plain text edit.
*/
ClearPlainTextEdit::ClearPlainTextEdit(QWidget *parent) :
QPlainTextEdit(parent),
ButtonOverlay(viewport())
ClearPlainTextEdit::ClearPlainTextEdit(QWidget *parent)
: QPlainTextEdit(parent)
, ButtonOverlay(viewport())
{
// set alignment to show buttons in the bottom right corner
ButtonOverlay::buttonLayout()->setAlignment(Qt::AlignBottom | Qt::AlignRight);
@ -32,7 +32,8 @@ ClearPlainTextEdit::ClearPlainTextEdit(QWidget *parent) :
* \brief Destroys the clear plain text edit.
*/
ClearPlainTextEdit::~ClearPlainTextEdit()
{}
{
}
/*!
* \brief Updates the visibility of the clear button.

View File

@ -7,8 +7,7 @@
namespace Widgets {
class QT_UTILITIES_EXPORT ClearPlainTextEdit : public QPlainTextEdit, public ButtonOverlay
{
class QT_UTILITIES_EXPORT ClearPlainTextEdit : public QPlainTextEdit, public ButtonOverlay {
Q_OBJECT
public:
explicit ClearPlainTextEdit(QWidget *parent = nullptr);
@ -19,7 +18,6 @@ private Q_SLOTS:
void handleTextChanged();
void handleClearButtonClicked();
void handleScroll();
};
} // namespace Widgets

View File

@ -15,10 +15,10 @@ namespace Widgets {
/*!
* \brief Constructs a clear spin box.
*/
ClearSpinBox::ClearSpinBox(QWidget *parent) :
QSpinBox(parent),
ButtonOverlay(this),
m_minimumHidden(false)
ClearSpinBox::ClearSpinBox(QWidget *parent)
: QSpinBox(parent)
, ButtonOverlay(this)
, m_minimumHidden(false)
{
const QMargins margins = contentsMargins();
QStyleOptionComboBox opt;
@ -26,7 +26,8 @@ ClearSpinBox::ClearSpinBox(QWidget *parent) :
const int frameWidth = style()->pixelMetric(QStyle::PM_SpinBoxFrameWidth, &opt, this);
const int pad = 5;
const int buttonWidth = style()->subControlRect(QStyle::CC_SpinBox, &opt, QStyle::SC_SpinBoxUp, this).width() + 10;
buttonLayout()->setContentsMargins(margins.left() + frameWidth + pad, margins.top() + frameWidth, margins.right() + frameWidth + pad + buttonWidth, margins.bottom() + frameWidth);
buttonLayout()->setContentsMargins(margins.left() + frameWidth + pad, margins.top() + frameWidth,
margins.right() + frameWidth + pad + buttonWidth, margins.bottom() + frameWidth);
setClearButtonEnabled(true);
connect(this, static_cast<void (ClearSpinBox::*)(int)>(&ClearSpinBox::valueChanged), this, &ClearSpinBox::handleValueChanged);
}
@ -35,7 +36,8 @@ ClearSpinBox::ClearSpinBox(QWidget *parent) :
* \brief Destroys the clear spin box.
*/
ClearSpinBox::~ClearSpinBox()
{}
{
}
/*!
* \brief Updates the visibility of the clear button.
@ -57,7 +59,7 @@ bool ClearSpinBox::isCleared() const
int ClearSpinBox::valueFromText(const QString &text) const
{
if(m_minimumHidden && text.isEmpty()) {
if (m_minimumHidden && text.isEmpty()) {
return minimum();
} else {
return QSpinBox::valueFromText(text);
@ -66,11 +68,10 @@ int ClearSpinBox::valueFromText(const QString &text) const
QString ClearSpinBox::textFromValue(int val) const
{
if(m_minimumHidden && (val == minimum())) {
if (m_minimumHidden && (val == minimum())) {
return QString();
} else {
return QSpinBox::textFromValue(val);
}
}
}

View File

@ -3,8 +3,8 @@
#include "./buttonoverlay.h"
#include <QSpinBox>
#include <QLineEdit>
#include <QSpinBox>
QT_FORWARD_DECLARE_CLASS(QHBoxLayout)
@ -12,8 +12,7 @@ namespace Widgets {
class IconButton;
class QT_UTILITIES_EXPORT ClearSpinBox : public QSpinBox, public ButtonOverlay
{
class QT_UTILITIES_EXPORT ClearSpinBox : public QSpinBox, public ButtonOverlay {
Q_OBJECT
Q_PROPERTY(bool minimumHidden READ minimumHidden WRITE setMinimumHidden)
Q_PROPERTY(QString placeholderText READ placeholderText WRITE setPlaceholderText)
@ -38,7 +37,6 @@ private Q_SLOTS:
private:
bool m_minimumHidden;
};
/*!
@ -74,7 +72,6 @@ inline void ClearSpinBox::setPlaceholderText(const QString &placeholderText)
{
lineEdit()->setPlaceholderText(placeholderText);
}
}
#endif // WIDGETS_CLEARSPINBOX_H

View File

@ -1,8 +1,8 @@
#include "./iconbutton.h"
#include <QStylePainter>
#include <QStyleOptionFocusRect>
#include <QKeyEvent>
#include <QStyleOptionFocusRect>
#include <QStylePainter>
namespace Widgets {
@ -14,8 +14,8 @@ namespace Widgets {
/*!
* \brief Constructs an icon button.
*/
IconButton::IconButton(QWidget *parent) :
QAbstractButton(parent)
IconButton::IconButton(QWidget *parent)
: QAbstractButton(parent)
{
setCursor(Qt::ArrowCursor);
setFocusPolicy(Qt::NoFocus);
@ -25,7 +25,8 @@ IconButton::IconButton(QWidget *parent) :
* \brief Destroys the icon button.
*/
IconButton::~IconButton()
{}
{
}
QSize IconButton::sizeHint() const
{
@ -48,7 +49,7 @@ void IconButton::paintEvent(QPaintEvent *)
QRect pixmapRect = QRect(0, 0, m_pixmap.width() / pixmapRatio, m_pixmap.height() / pixmapRatio);
pixmapRect.moveCenter(rect().center());
painter.drawPixmap(pixmapRect, m_pixmap);
if(hasFocus()) {
if (hasFocus()) {
QStyleOptionFocusRect focusOption;
focusOption.initFrom(this);
focusOption.rect = pixmapRect;
@ -75,5 +76,4 @@ void IconButton::keyReleaseEvent(QKeyEvent *event)
QAbstractButton::keyReleaseEvent(event);
event->accept();
}
}

View File

@ -8,8 +8,7 @@
namespace Widgets {
class QT_UTILITIES_EXPORT IconButton : public QAbstractButton
{
class QT_UTILITIES_EXPORT IconButton : public QAbstractButton {
Q_OBJECT
Q_PROPERTY(QPixmap pixmap READ pixmap WRITE setPixmap)
@ -46,7 +45,6 @@ inline void IconButton::setPixmap(const QPixmap &pixmap)
m_pixmap = pixmap;
update();
}
}
#endif // WIDGETS_ICONBUTTON_H

View File

@ -5,15 +5,15 @@
#include <c++utilities/io/path.h>
#include <QHBoxLayout>
#include <QPushButton>
#include <QFileDialog>
#include <QMenu>
#include <QCompleter>
#include <QFileDialog>
#include <QFileSystemModel>
#include <QHBoxLayout>
#include <QMenu>
#include <QPushButton>
#include <QStringBuilder>
#ifndef QT_NO_CONTEXTMENU
# include <QContextMenuEvent>
#include <QContextMenuEvent>
#endif
#include <memory>
@ -32,14 +32,14 @@ QCompleter *PathSelection::m_completer = nullptr;
/*!
* \brief Constructs a path selection widget.
*/
PathSelection::PathSelection(QWidget *parent) :
QWidget(parent),
m_lineEdit(new ClearLineEdit(this)),
m_button(new QPushButton(this)),
m_customMode(QFileDialog::Directory),
m_customDialog(nullptr)
PathSelection::PathSelection(QWidget *parent)
: QWidget(parent)
, m_lineEdit(new ClearLineEdit(this))
, m_button(new QPushButton(this))
, m_customMode(QFileDialog::Directory)
, m_customDialog(nullptr)
{
if(!m_completer) {
if (!m_completer) {
auto *fileSystemModel = new QFileSystemModel(m_completer);
fileSystemModel->setRootPath(QString());
m_completer = new QCompleter;
@ -66,25 +66,27 @@ PathSelection::PathSelection(QWidget *parent) :
bool PathSelection::eventFilter(QObject *obj, QEvent *event)
{
#ifndef QT_NO_CONTEXTMENU
if(obj == m_lineEdit) {
switch(event->type()) {
if (obj == m_lineEdit) {
switch (event->type()) {
case QEvent::ContextMenu: {
unique_ptr<QMenu> menu(m_lineEdit->createStandardContextMenu());
menu->addSeparator();
connect(menu->addAction(QIcon::fromTheme(QStringLiteral("document-open")), tr("Select ...")), &QAction::triggered, this, &PathSelection::showFileDialog);
connect(menu->addAction(QIcon::fromTheme(QStringLiteral("document-open")), tr("Select ...")), &QAction::triggered, this,
&PathSelection::showFileDialog);
QFileInfo fileInfo(m_lineEdit->text());
if(fileInfo.exists()) {
if(fileInfo.isFile()) {
connect(menu->addAction(QIcon::fromTheme(QStringLiteral("system-run")), tr("Open")), &QAction::triggered, bind(&DesktopUtils::openLocalFileOrDir, m_lineEdit->text()));
} else if(fileInfo.isDir()) {
connect(menu->addAction(QIcon::fromTheme(QStringLiteral("system-file-manager")), tr("Explore")), &QAction::triggered, bind(&DesktopUtils::openLocalFileOrDir, m_lineEdit->text()));
if (fileInfo.exists()) {
if (fileInfo.isFile()) {
connect(menu->addAction(QIcon::fromTheme(QStringLiteral("system-run")), tr("Open")), &QAction::triggered,
bind(&DesktopUtils::openLocalFileOrDir, m_lineEdit->text()));
} else if (fileInfo.isDir()) {
connect(menu->addAction(QIcon::fromTheme(QStringLiteral("system-file-manager")), tr("Explore")), &QAction::triggered,
bind(&DesktopUtils::openLocalFileOrDir, m_lineEdit->text()));
}
}
menu->exec(static_cast<QContextMenuEvent *>(event)->globalPos());
}
return true;
default:
;
default:;
}
}
#endif
@ -95,16 +97,16 @@ void PathSelection::showFileDialog()
{
QString directory;
QFileInfo fileInfo(m_lineEdit->text());
if(fileInfo.exists()) {
if(fileInfo.isFile()) {
if (fileInfo.exists()) {
if (fileInfo.isFile()) {
directory = fileInfo.absoluteDir().absolutePath();
} else {
directory = fileInfo.absolutePath();
}
}
if(m_customDialog) {
if (m_customDialog) {
m_customDialog->setDirectory(directory);
if(m_customDialog->exec() == QFileDialog::Accepted) {
if (m_customDialog->exec() == QFileDialog::Accepted) {
m_lineEdit->selectAll();
m_lineEdit->insert(m_customDialog->selectedFiles().join(SEARCH_PATH_SEP_CHAR));
}
@ -112,16 +114,15 @@ void PathSelection::showFileDialog()
QFileDialog dialog(this);
dialog.setDirectory(directory);
dialog.setFileMode(m_customMode);
if(window()) {
if (window()) {
dialog.setWindowTitle(tr("Select path") % QStringLiteral(" - ") % window()->windowTitle());
} else {
dialog.setWindowTitle(tr("Select path"));
}
if(dialog.exec() == QFileDialog::Accepted) {
if (dialog.exec() == QFileDialog::Accepted) {
m_lineEdit->selectAll();
m_lineEdit->insert(dialog.selectedFiles().join(SEARCH_PATH_SEP_CHAR));
}
}
}
}

View File

@ -12,8 +12,7 @@ namespace Widgets {
class ClearLineEdit;
class QT_UTILITIES_EXPORT PathSelection : public QWidget
{
class QT_UTILITIES_EXPORT PathSelection : public QWidget {
Q_OBJECT
public:
explicit PathSelection(QWidget *parent = nullptr);
@ -72,7 +71,6 @@ inline void PathSelection::provideCustomFileDialog(QFileDialog *customFileDialog
{
m_customDialog = customFileDialog;
}
}
#endif // WIDGETS_PATHSELECTION_H