2018-08-23 00:24:55 +08:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <QString>
|
2018-10-10 19:03:15 +08:00
|
|
|
#include <QVector>
|
2018-11-02 02:46:37 +08:00
|
|
|
#include <QHash>
|
2018-11-02 02:07:42 +08:00
|
|
|
#include <QFile>
|
2018-12-02 04:55:32 +08:00
|
|
|
#include <QFileInfo>
|
2019-01-12 06:14:49 +08:00
|
|
|
#include <QDir>
|
2019-06-29 11:16:31 +08:00
|
|
|
#include <QSettings>
|
|
|
|
#include <QMainWindow>
|
|
|
|
#include <QDialog>
|
2021-01-21 22:07:09 +08:00
|
|
|
#include <QApplication>
|
2019-06-29 11:16:31 +08:00
|
|
|
#include <QLayout>
|
|
|
|
#include <QFormLayout>
|
|
|
|
#include <QLabel>
|
|
|
|
#include <QPushButton>
|
|
|
|
#include <QCheckBox>
|
|
|
|
#include <QSpinBox>
|
|
|
|
#include <QListWidget>
|
|
|
|
#include <QMessageBox>
|
|
|
|
#include <QInputDialog>
|
2019-03-13 23:44:21 +08:00
|
|
|
|
2019-09-17 05:14:59 +08:00
|
|
|
static thread_local bool ok;
|
|
|
|
|
2020-03-05 16:51:36 +08:00
|
|
|
constexpr auto CONFIG_FILE = u8"Textractor.ini";
|
|
|
|
constexpr auto WINDOW = u8"Window";
|
|
|
|
|
2020-11-02 21:27:21 +08:00
|
|
|
struct Settings : QSettings { Settings(QObject* parent = nullptr) : QSettings(CONFIG_FILE, QSettings::IniFormat, parent) {} };
|
2019-03-13 23:44:21 +08:00
|
|
|
struct QTextFile : QFile { QTextFile(QString name, QIODevice::OpenMode mode) : QFile(name) { open(mode | QIODevice::Text); } };
|
2021-01-21 22:07:09 +08:00
|
|
|
struct Localizer { Localizer() { Localize(); } };
|
2020-01-19 14:25:57 +08:00
|
|
|
inline std::wstring S(const QString& s) { return { s.toStdWString() }; }
|
|
|
|
inline QString S(const std::string& s) { return QString::fromStdString(s); }
|
|
|
|
inline QString S(const std::wstring& s) { return QString::fromStdWString(s); }
|
|
|
|
// TODO: allow paired surrogates
|
|
|
|
inline void sanitize(QString& s) { s.chop(std::distance(std::remove_if(s.begin(), s.end(), [](QChar ch) { return ch.isSurrogate(); }), s.end())); }
|
2020-09-10 04:54:15 +08:00
|
|
|
inline QString sanitize(QString&& s) { sanitize(s); return std::move(s); }
|