qad_types доработки
This commit is contained in:
@@ -4,7 +4,7 @@ cmake_policy(SET CMP0072 NEW) # FindOpenGL prefers GLVND by default
|
||||
project(qad)
|
||||
set(qad_MAJOR 2)
|
||||
set(qad_MINOR 8)
|
||||
set(qad_REVISION 0)
|
||||
set(qad_REVISION 1)
|
||||
set(qad_SUFFIX )
|
||||
set(qad_COMPANY SHS)
|
||||
set(qad_DOMAIN org.SHS)
|
||||
|
||||
@@ -65,61 +65,61 @@ QAD::Enum::Enum(const QMetaEnum & meta, int selected) {
|
||||
|
||||
|
||||
int QAD::Enum::selectedValue() const {
|
||||
foreach (const Enumerator & e, enum_list)
|
||||
if (e.name == selected)
|
||||
return e.value;
|
||||
for (const Enumerator & e : enum_list) {
|
||||
if (e.name == selected) return e.value;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
bool QAD::Enum::selectValue(int v) {
|
||||
foreach (const Enumerator & e, enum_list)
|
||||
for (const Enumerator & e : enum_list) {
|
||||
if (e.value == v) {
|
||||
selected = e.name;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool QAD::Enum::selectName(const QString & n) {
|
||||
foreach (const Enumerator & e, enum_list)
|
||||
for (const Enumerator & e : enum_list) {
|
||||
if (e.name == n) {
|
||||
selected = e.name;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
int QAD::Enum::value(const QString & n) const {
|
||||
foreach (const Enumerator & e, enum_list)
|
||||
if (e.name == n)
|
||||
return e.value;
|
||||
for (const Enumerator & e : enum_list) {
|
||||
if (e.name == n) return e.value;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
QString QAD::Enum::name(int v) const {
|
||||
foreach (const Enumerator & e, enum_list)
|
||||
if (e.value == v)
|
||||
return e.name;
|
||||
for (const Enumerator & e : enum_list) {
|
||||
if (e.value == v) return e.name;
|
||||
}
|
||||
return QString();
|
||||
}
|
||||
|
||||
|
||||
QList<int> QAD::Enum::values() const {
|
||||
QList<int> ret;
|
||||
foreach (const Enumerator & e, enum_list)
|
||||
ret << e.value;
|
||||
for (const Enumerator & e : enum_list) ret << e.value;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
QStringList QAD::Enum::names() const {
|
||||
QStringList ret;
|
||||
foreach (const Enumerator & e, enum_list)
|
||||
ret << e.name;
|
||||
for (const Enumerator & e : enum_list) ret << e.name;
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -137,8 +137,7 @@ QAD::Enum & QAD::Enum::operator <<(const QString & v) {
|
||||
|
||||
|
||||
QAD::Enum & QAD::Enum::operator <<(const QStringList & v) {
|
||||
foreach (const QString & s, v)
|
||||
(*this) << s;
|
||||
for (const QString & s : v) (*this) << s;
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -151,32 +150,8 @@ QString QAD::IODevice::toString() const {
|
||||
QVariant v;
|
||||
v.setValue(*this);
|
||||
(*(__QADTypesRegistrator__::instance()->toString_funcs[qMetaTypeId<QAD::IODevice>()]))(v, s);
|
||||
return s;
|
||||
} else {
|
||||
// s += "IODevice(" + prefix + ", mode=";
|
||||
// int rwc = 0;
|
||||
// if (mode & QIODevice::ReadOnly) {s += "r"; ++rwc;}
|
||||
// if (mode & QIODevice::WriteOnly) {s += "w"; ++rwc;}
|
||||
// if (rwc == 1) s += "o";
|
||||
// if (options != 0) {
|
||||
// s += ", flags=";
|
||||
// if (options & 1)
|
||||
// s += "br";
|
||||
// if (options & 2)
|
||||
// if (options & 1)
|
||||
// s+= "|";
|
||||
// s += "bw";
|
||||
// }
|
||||
// PropertyStorage ps = props;
|
||||
// foreach (const PropertyStorage::Property & p, ps) {
|
||||
// QString vs = p.value.toString();
|
||||
// if (p.value.type() == QVariant::StringList)
|
||||
// vs = p.value.toStringList().join(";");
|
||||
// s += ", " + p.name + "=\"" + vs + "\"";
|
||||
// }
|
||||
// s += ")";
|
||||
return s;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
@@ -231,8 +206,7 @@ QMetaType
|
||||
|
||||
|
||||
QString uniqueName(QString n, const QStringList & names) {
|
||||
if (!names.contains(n))
|
||||
return n;
|
||||
if (!names.contains(n)) return n;
|
||||
QString num;
|
||||
while (!n.isEmpty()) {
|
||||
if (n.right(1)[0].isDigit()) {
|
||||
@@ -240,60 +214,42 @@ QString uniqueName(QString n, const QStringList & names) {
|
||||
n.chop(1);
|
||||
} else break;
|
||||
}
|
||||
if (!n.endsWith('_')) n += '_';
|
||||
if (!n.endsWith('_') && num.isEmpty()) n += '_';
|
||||
int in = num.toInt() + 1;
|
||||
QString nn = n + QString::number(in).rightJustified(3, '0');
|
||||
QString nn = n + QString::number(in);
|
||||
while (names.contains(nn))
|
||||
nn = n + QString::number(++in).rightJustified(3, '0');
|
||||
nn = n + QString::number(++in);
|
||||
return nn;
|
||||
}
|
||||
|
||||
|
||||
int fontHeight(const QWidget * w) {
|
||||
int fontHeight(const QWidget * window) {
|
||||
#ifdef Q_OS_ANDROID
|
||||
static int ret = QApplication::fontMetrics().size(0, "0").height();
|
||||
static int ret = QApplication::fontMetrics().height();
|
||||
return ret;
|
||||
#else
|
||||
# if QT_VERSION >= 0x050000
|
||||
//qDebug() << "fontHeight" << w;
|
||||
if (w) {
|
||||
QWidget * pw = w->window();
|
||||
if (pw) {
|
||||
/*QWindow * wnd = pw->windowHandle();
|
||||
//qDebug() << "wnd" << wnd;
|
||||
if (wnd) {
|
||||
QScreen * s = wnd->screen();
|
||||
qDebug() << "s" << s;
|
||||
if (s) {
|
||||
qDebug() << "scales:";
|
||||
qDebug() << QApplication::fontMetrics().size(0, "0").height() << QApplication::fontMetrics().xHeight();
|
||||
qDebug() << s->logicalDotsPerInch() << s->logicalDotsPerInch()/96.*QApplication::font().pointSizeF();
|
||||
}
|
||||
}*/
|
||||
return QFontMetrics(QApplication::font(), pw).size(0, "0").height()
|
||||
#if QT_VERSION_MAJOR == 6
|
||||
/ 1.25
|
||||
#endif
|
||||
;
|
||||
}
|
||||
}
|
||||
# if QT_VERSION_MAJOR == 6
|
||||
double add_scale = 0.8;
|
||||
# else
|
||||
double add_scale = 1.0;
|
||||
# endif
|
||||
#endif
|
||||
#if QT_VERSION_MAJOR <= 5
|
||||
return QApplication::fontMetrics().size(0, "0").height();
|
||||
#else
|
||||
return QFontMetricsF(QApplication::font()).size(0, "0").height();
|
||||
//qDebug() << "fontHeight" << w;
|
||||
if (window) {
|
||||
QWidget * pw = window->window();
|
||||
if (pw) return QFontMetrics(pw->font()).height() * add_scale;
|
||||
}
|
||||
return QFontMetrics(QApplication::font()).height() * add_scale;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
int lineThickness(const QWidget * w) {
|
||||
return qMax<int>(qRound(fontHeight(w) / 15.), 1);
|
||||
int lineThickness(const QWidget * window) {
|
||||
return qMax<int>(qRound(fontHeight(window) / 15.), 1);
|
||||
}
|
||||
|
||||
|
||||
QSize preferredIconSize(float x, const QWidget * w) {
|
||||
int s = qMax<int>(8, qRound(fontHeight(w) * x));
|
||||
QSize preferredIconSize(float x, const QWidget * window) {
|
||||
int s = qMax<int>(8, qRound(fontHeight(window) * x));
|
||||
#ifdef Q_OS_MACOS
|
||||
s /= 1.25;
|
||||
#endif
|
||||
@@ -304,8 +260,8 @@ QSize preferredIconSize(float x, const QWidget * w) {
|
||||
}
|
||||
|
||||
|
||||
double appScale(const QWidget * w) {
|
||||
return qMax<double>(fontHeight(w) / 15., 1.);
|
||||
double appScale(const QWidget * window) {
|
||||
return qMax<double>(fontHeight(window) / 15., 1.);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -219,10 +219,10 @@ QAD_UTILS_EXPORT
|
||||
typeFromLetter(const QString & l);
|
||||
QAD_UTILS_EXPORT QString uniqueName(QString n, const QStringList & names);
|
||||
|
||||
QAD_UTILS_EXPORT int fontHeight(const QWidget * w = 0);
|
||||
QAD_UTILS_EXPORT int lineThickness(const QWidget * w = 0);
|
||||
QAD_UTILS_EXPORT QSize preferredIconSize(float x = 1.f, const QWidget * w = 0);
|
||||
QAD_UTILS_EXPORT double appScale(const QWidget * w = 0);
|
||||
QAD_UTILS_EXPORT int fontHeight(const QWidget * window = nullptr);
|
||||
QAD_UTILS_EXPORT int lineThickness(const QWidget * window = nullptr);
|
||||
QAD_UTILS_EXPORT QSize preferredIconSize(float x = 1.f, const QWidget * window = nullptr);
|
||||
QAD_UTILS_EXPORT double appScale(const QWidget * window = nullptr);
|
||||
QAD_UTILS_EXPORT void enableHighDPI();
|
||||
QAD_UTILS_EXPORT const QMetaObject * getQtMetaObject();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user