Changeset View
Changeset View
Standalone View
Standalone View
src/EditProfileDialog.cpp
Show First 20 Lines • Show All 956 Lines • ▼ Show 20 Line(s) | 950 | { | |||
---|---|---|---|---|---|
957 | } | 957 | } | ||
958 | 958 | | |||
959 | return QDialog::eventFilter(watched, event); | 959 | return QDialog::eventFilter(watched, event); | ||
960 | } | 960 | } | ||
961 | 961 | | |||
962 | QSize EditProfileDialog::sizeHint() const | 962 | QSize EditProfileDialog::sizeHint() const | ||
963 | { | 963 | { | ||
964 | QFontMetrics fm(font()); | 964 | QFontMetrics fm(font()); | ||
965 | const int ch = fm.width(QLatin1Char('0')); | 965 | const int ch = fm.boundingRect(QLatin1Char('0')).width(); | ||
966 | 966 | | |||
967 | // By default minimum size is used. Increase it to make text inputs | 967 | // By default minimum size is used. Increase it to make text inputs | ||
968 | // on "tabs" page wider and to add some whitespace on right side | 968 | // on "tabs" page wider and to add some whitespace on right side | ||
969 | // of other pages. The window will not be wider than 2/3 of | 969 | // of other pages. The window will not be wider than 2/3 of | ||
970 | // the screen width (unless necessary to fit everything) | 970 | // the screen width (unless necessary to fit everything) | ||
971 | return QDialog::sizeHint() + QSize(10*ch, 0); | 971 | return QDialog::sizeHint() + QSize(10*ch, 0); | ||
972 | } | 972 | } | ||
973 | 973 | | |||
▲ Show 20 Lines • Show All 757 Lines • ▼ Show 20 Line(s) | |||||
1731 | { | 1731 | { | ||
1732 | static const int cursorWidth = 2; | 1732 | static const int cursorWidth = 2; | ||
1733 | 1733 | | |||
1734 | const QFontMetrics fm(spinBox->fontMetrics()); | 1734 | const QFontMetrics fm(spinBox->fontMetrics()); | ||
1735 | const QString plural = suffix.subs(2).toString(); | 1735 | const QString plural = suffix.subs(2).toString(); | ||
1736 | const QString singular = suffix.subs(1).toString(); | 1736 | const QString singular = suffix.subs(1).toString(); | ||
1737 | const QString min = QString::number(spinBox->minimum()); | 1737 | const QString min = QString::number(spinBox->minimum()); | ||
1738 | const QString max = QString::number(spinBox->maximum()); | 1738 | const QString max = QString::number(spinBox->maximum()); | ||
1739 | const int pluralWidth = fm.width(plural); | 1739 | const int pluralWidth = fm.boundingRect(plural).width(); | ||
1740 | const int singularWidth = fm.width(singular); | 1740 | const int singularWidth = fm.boundingRect(singular).width(); | ||
1741 | const int minWidth = fm.width(min); | 1741 | const int minWidth = fm.boundingRect(min).width(); | ||
1742 | const int maxWidth = fm.width(max); | 1742 | const int maxWidth = fm.boundingRect(max).width(); | ||
1743 | const int width = qMax(pluralWidth, singularWidth) + qMax(minWidth, maxWidth) + cursorWidth; | 1743 | const int width = qMax(pluralWidth, singularWidth) + qMax(minWidth, maxWidth) + cursorWidth; | ||
1744 | 1744 | | |||
1745 | // Based on QAbstractSpinBox::initStyleOption() from Qt | 1745 | // Based on QAbstractSpinBox::initStyleOption() from Qt | ||
1746 | QStyleOptionSpinBox opt; | 1746 | QStyleOptionSpinBox opt; | ||
1747 | opt.initFrom(spinBox); | 1747 | opt.initFrom(spinBox); | ||
1748 | opt.activeSubControls = QStyle::SC_None; | 1748 | opt.activeSubControls = QStyle::SC_None; | ||
1749 | opt.buttonSymbols = spinBox->buttonSymbols(); | 1749 | opt.buttonSymbols = spinBox->buttonSymbols(); | ||
1750 | // Assume all spinboxes have buttons | 1750 | // Assume all spinboxes have buttons | ||
▲ Show 20 Lines • Show All 149 Lines • ▼ Show 20 Line(s) | 1885 | { | |||
1900 | QPalette::ColorRole textColor = ((option.state & QStyle::State_Selected) != 0) | 1900 | QPalette::ColorRole textColor = ((option.state & QStyle::State_Selected) != 0) | ||
1901 | ? QPalette::HighlightedText : QPalette::Text; | 1901 | ? QPalette::HighlightedText : QPalette::Text; | ||
1902 | painter->setPen(option.palette.color(textColor)); | 1902 | painter->setPen(option.palette.color(textColor)); | ||
1903 | painter->setFont(option.font); | 1903 | painter->setFont(option.font); | ||
1904 | 1904 | | |||
1905 | // Determine width of sample text using profile's font | 1905 | // Determine width of sample text using profile's font | ||
1906 | const QString sampleText = i18n("AaZz09..."); | 1906 | const QString sampleText = i18n("AaZz09..."); | ||
1907 | QFontMetrics profileFontMetrics(profileFont); | 1907 | QFontMetrics profileFontMetrics(profileFont); | ||
1908 | const int sampleTextWidth = profileFontMetrics.width(sampleText); | 1908 | const int sampleTextWidth = profileFontMetrics.boundingRect(sampleText).width(); | ||
1909 | 1909 | | |||
1910 | painter->drawText(option.rect.adjusted(sampleTextWidth + 15, 0, 0, 0), | 1910 | painter->drawText(option.rect.adjusted(sampleTextWidth + 15, 0, 0, 0), | ||
1911 | Qt::AlignLeft | Qt::AlignVCenter, | 1911 | Qt::AlignLeft | Qt::AlignVCenter, | ||
1912 | index.data(Qt::DisplayRole).toString()); | 1912 | index.data(Qt::DisplayRole).toString()); | ||
1913 | 1913 | | |||
1914 | // Draw the preview | 1914 | // Draw the preview | ||
1915 | const int x = option.rect.left(); | 1915 | const int x = option.rect.left(); | ||
1916 | const int y = option.rect.top(); | 1916 | const int y = option.rect.top(); | ||
Show All 39 Lines |