17 #include <QApplication>
20 #include <QFontMetrics>
22 #include <QMainWindow>
29 QSize FindSizeOfLetterM()
31 QFontMetrics fontMetric(QApplication::font());
32 auto em = fontMetric.horizontalAdvance(
'M');
33 auto fontAscent = fontMetric.ascent();
34 return QSize(em, fontAscent);
37 const QString untitled_name =
"Untitled";
44 return QColor(rndm(), rndm(), rndm());
72 #if defined(Q_OS_LINUX)
84 static const QString homePath = QDir::homePath();
86 QFileInfo fi(QDir::cleanPath(path));
87 QString outPath = fi.absoluteFilePath();
88 if (outPath.startsWith(homePath))
89 outPath = QLatin1Char(
'~') + outPath.mid(homePath.size());
100 auto pos = project_dir.lastIndexOf(
'/');
101 auto project_name = (pos == -1) ? untitled_name : project_dir.mid(pos + 1);
102 auto unsaved_status = is_modified ? QString(
"*") : QString();
103 return unsaved_status + project_name;
118 static QSize result = FindSizeOfLetterM();
124 return QApplication::font().pointSize();
129 for (
auto widget : qApp->topLevelWidgets()) {
130 if (
auto result =
dynamic_cast<QMainWindow*
>(widget); result)
138 return QString(
"<a href=\"%1\">%2</a>").arg(tag.isEmpty() ? text : tag, text);
143 QFont font = label->font();
145 label->setFont(font);
151 for (
const auto& x : vec)
152 result.push_back(QString::fromStdString(x));
158 std::vector<std::string> result;
159 for (
const auto& x : string_list)
160 result.push_back(x.toStdString());
166 QByteArray byteArray;
167 QDataStream out(&byteArray, QIODevice::WriteOnly);
174 QByteArray array = byteArray;
176 QDataStream in(&array, QIODevice::ReadOnly);
MVVM_VIEW_EXPORT std::string RandomNamedColor()
Returns the name of random color.
MVVM_VIEW_EXPORT int HeightOfLetterM()
Returns height of the letter 'M' deduced from current font metrics.
MVVM_VIEW_EXPORT QStringList deserialize(const QByteArray &byteArray)
Converts byte array to vector of strings.
MVVM_VIEW_EXPORT QString WithTildeHomePath(const QString &path)
Returns a string where Linux path to the file is striped using '~/'.
MVVM_VIEW_EXPORT bool IsWindowsHost()
Returns true if it is Windows.
MVVM_VIEW_EXPORT QSize SizeOfLetterM()
Returns size corresponding to actual size of letter M basing on current font metrics.
MVVM_VIEW_EXPORT bool IsMacHost()
Returns true if it is Mac.
MVVM_VIEW_EXPORT QByteArray serialize(const QStringList &data)
Converts vector of strings to byte array.
MVVM_VIEW_EXPORT QStringList toStringList(const std::vector< std::string > &vec)
Converts vector of strings to QStringList.
MVVM_VIEW_EXPORT QString ClickableText(const QString &text, const QString &tag={})
Returns text wrapped into 'href' tag to provide clickable links in QLabel.
MVVM_VIEW_EXPORT void ScaleLabelFont(QLabel *label, double scale)
Set label's font size to system font size scaled by given factor.
MVVM_VIEW_EXPORT QMainWindow * FindMainWindow()
Finds main window.
MVVM_VIEW_EXPORT QColor RandomColor()
Returns random color.
MVVM_VIEW_EXPORT std::vector< std::string > fromStringList(const QStringList &string_list)
Converts vector of strings to QStringList.
MVVM_VIEW_EXPORT int WidthOfLetterM()
Returns width of the letter 'M' deduced from current font metrics.
MVVM_VIEW_EXPORT bool IsLinuxHost()
Returns true if it is Linux.
MVVM_VIEW_EXPORT int SystemPointSize()
Returns size in points of default system font.
MVVM_MODEL_EXPORT int RandInt(int low, int high)
Produces random integer values uniformly distributed on the closed interval [low, high].
MVVM_VIEW_EXPORT QString ProjectWindowTitle(const QString &project_dir, bool is_modified)
Returns a title composed from last part of project path, and is_modified flag.