2017-03-29 10:18:37 +00:00
|
|
|
#ifndef QHELPERS_H
|
|
|
|
#define QHELPERS_H
|
|
|
|
|
2020-08-01 14:14:30 +00:00
|
|
|
#include "core/CutterCommon.h"
|
|
|
|
|
2017-04-13 15:04:30 +00:00
|
|
|
#include <QString>
|
2017-12-03 14:46:22 +00:00
|
|
|
#include <QColor>
|
2017-11-03 17:22:54 +00:00
|
|
|
#include <QSizePolicy>
|
2019-04-27 17:58:44 +00:00
|
|
|
#include <functional>
|
2017-04-13 15:04:30 +00:00
|
|
|
|
2019-04-27 17:58:44 +00:00
|
|
|
class QIcon;
|
2017-04-05 08:56:59 +00:00
|
|
|
class QPlainTextEdit;
|
|
|
|
class QTextEdit;
|
2017-04-18 10:03:47 +00:00
|
|
|
class QString;
|
2017-04-13 15:04:30 +00:00
|
|
|
class QTreeWidget;
|
2017-04-28 13:09:40 +00:00
|
|
|
class QTreeWidgetItem;
|
|
|
|
class QAbstractItemView;
|
2020-11-19 18:17:28 +00:00
|
|
|
class QAbstractItemModel;
|
2017-10-01 14:36:40 +00:00
|
|
|
class QAbstractButton;
|
2017-11-03 17:22:54 +00:00
|
|
|
class QWidget;
|
2017-12-23 16:42:42 +00:00
|
|
|
class QTreeView;
|
2019-09-25 14:18:30 +00:00
|
|
|
class QAction;
|
|
|
|
class QMenu;
|
2019-10-06 17:35:44 +00:00
|
|
|
class QPaintDevice;
|
2020-01-04 18:05:49 +00:00
|
|
|
class QComboBox;
|
2017-03-29 10:18:37 +00:00
|
|
|
|
2020-06-06 16:02:24 +00:00
|
|
|
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
|
|
|
|
#define CUTTER_QT_SKIP_EMPTY_PARTS QString::SkipEmptyParts
|
|
|
|
#else
|
|
|
|
#define CUTTER_QT_SKIP_EMPTY_PARTS Qt::SkipEmptyParts
|
|
|
|
#endif
|
|
|
|
|
2018-03-21 20:32:32 +00:00
|
|
|
namespace qhelpers {
|
2020-08-01 14:14:30 +00:00
|
|
|
CUTTER_EXPORT QString formatBytecount(const uint64_t bytecount);
|
|
|
|
CUTTER_EXPORT void adjustColumns(QTreeView *tv, int columnCount, int padding);
|
|
|
|
CUTTER_EXPORT void adjustColumns(QTreeWidget *tw, int padding);
|
|
|
|
CUTTER_EXPORT bool selectFirstItem(QAbstractItemView *itemView);
|
|
|
|
CUTTER_EXPORT QTreeWidgetItem *appendRow(QTreeWidget *tw, const QString &str, const QString &str2 = QString(),
|
2018-03-21 20:32:32 +00:00
|
|
|
const QString &str3 = QString(), const QString &str4 = QString(), const QString &str5 = QString());
|
2017-04-13 15:04:30 +00:00
|
|
|
|
2020-08-01 14:14:30 +00:00
|
|
|
CUTTER_EXPORT void setVerticalScrollMode(QAbstractItemView *tw);
|
2017-10-01 14:36:40 +00:00
|
|
|
|
2020-08-01 14:14:30 +00:00
|
|
|
CUTTER_EXPORT void setCheckedWithoutSignals(QAbstractButton *button, bool checked);
|
2017-11-03 17:22:54 +00:00
|
|
|
|
|
|
|
|
2020-08-01 14:14:30 +00:00
|
|
|
struct CUTTER_EXPORT SizePolicyMinMax {
|
2018-03-21 20:32:32 +00:00
|
|
|
QSizePolicy sizePolicy;
|
|
|
|
int min;
|
|
|
|
int max;
|
2017-11-03 17:22:54 +00:00
|
|
|
|
2018-03-21 20:32:32 +00:00
|
|
|
void restoreWidth(QWidget *widget);
|
|
|
|
void restoreHeight(QWidget *widget);
|
|
|
|
};
|
2017-11-03 17:22:54 +00:00
|
|
|
|
2020-08-01 14:14:30 +00:00
|
|
|
CUTTER_EXPORT SizePolicyMinMax forceWidth(QWidget *widget, int width);
|
|
|
|
CUTTER_EXPORT SizePolicyMinMax forceHeight(QWidget *widget, int height);
|
2017-11-15 21:56:10 +00:00
|
|
|
|
2020-08-01 14:14:30 +00:00
|
|
|
CUTTER_EXPORT int getMaxFullyDisplayedLines(QTextEdit *textEdit);
|
|
|
|
CUTTER_EXPORT int getMaxFullyDisplayedLines(QPlainTextEdit *plainTextEdit);
|
2017-12-03 14:46:22 +00:00
|
|
|
|
2020-08-01 14:14:30 +00:00
|
|
|
CUTTER_EXPORT QByteArray applyColorToSvg(const QByteArray &data, QColor color);
|
|
|
|
CUTTER_EXPORT QByteArray applyColorToSvg(const QString &filename, QColor color);
|
2019-04-27 17:58:44 +00:00
|
|
|
|
2020-08-01 14:14:30 +00:00
|
|
|
CUTTER_EXPORT void setThemeIcons(QList<QPair<void*, QString>> supportedIconsNames, std::function<void(void *, const QIcon &)> setter);
|
2019-04-27 17:58:44 +00:00
|
|
|
|
2020-08-01 14:14:30 +00:00
|
|
|
CUTTER_EXPORT void prependQAction(QAction *action, QMenu *menu);
|
|
|
|
CUTTER_EXPORT qreal devicePixelRatio(const QPaintDevice *p);
|
2020-01-04 18:05:49 +00:00
|
|
|
/**
|
|
|
|
* @brief Select comboBox item by value in Qt::UserRole.
|
|
|
|
* @param comboBox
|
|
|
|
* @param data - value to search in combobox item data
|
|
|
|
* @param defaultIndex - item to select in case no match
|
|
|
|
*/
|
2020-08-01 14:14:30 +00:00
|
|
|
CUTTER_EXPORT void selectIndexByData(QComboBox *comboBox, QVariant data, int defaultIndex = -1);
|
2020-11-19 18:17:28 +00:00
|
|
|
/**
|
|
|
|
* @brief Emit data change signal in a model's column (DisplayRole)
|
|
|
|
* @param model - model containing data with changes
|
|
|
|
* @param column - column in the model
|
|
|
|
*/
|
|
|
|
CUTTER_EXPORT void emitColumnChanged(QAbstractItemModel *model, int column);
|
2019-09-25 14:18:30 +00:00
|
|
|
|
2019-04-27 17:58:44 +00:00
|
|
|
} // qhelpers
|
2017-03-29 10:18:37 +00:00
|
|
|
|
|
|
|
#endif // HELPERS_H
|