Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Utilities
KCalc
Commits
6c3b4763
Commit
6c3b4763
authored
Sep 09, 2021
by
Niklas Freund
Browse files
Implemented scaling of KCalcDisplay on resize
parent
c82f5857
Changes
5
Hide whitespace changes
Inline
Side-by-side
kcalc.cpp
View file @
6c3b4763
...
...
@@ -2687,6 +2687,7 @@ int main(int argc, char *argv[])
QStringLiteral
(
"ochominutosdearco@yahoo.es"
));
aboutData
.
addAuthor
(
i18n
(
"Michel Marti"
),
QString
(),
QStringLiteral
(
"mma@objectxp.com"
));
aboutData
.
addAuthor
(
i18n
(
"David Johnson"
),
QString
(),
QStringLiteral
(
"david@usermode.org"
));
aboutData
.
addAuthor
(
i18n
(
"Niklas Freund"
),
QString
(),
QStringLiteral
(
"nalquas.dev@gmail.com"
));
KAboutData
::
setApplicationData
(
aboutData
);
app
.
setWindowIcon
(
QIcon
::
fromTheme
(
QStringLiteral
(
"accessories-calculator"
),
app
.
windowIcon
()));
...
...
kcalc.h
View file @
6c3b4763
...
...
@@ -106,6 +106,9 @@ public:
Q_DECLARE_FLAGS
(
UpdateFlags
,
UpdateFlag
)
protected:
void
resizeEvent
(
QResizeEvent
*
event
)
override
;
private:
bool
eventFilter
(
QObject
*
o
,
QEvent
*
e
)
override
;
bool
event
(
QEvent
*
e
)
override
;
...
...
@@ -126,8 +129,6 @@ private:
void
setAngle
();
void
setBase
();
void
resizeEvent
(
QResizeEvent
*
event
)
override
;
void
updateDisplay
(
UpdateFlags
flags
);
void
updateHistoryWithFunction
(
CalcEngine
::
Operation
);
KCalcStatusBar
*
statusBar
();
...
...
kcalc.ui
View file @
6c3b4763
...
...
@@ -24,11 +24,11 @@
<enum>
QLayout::SetMinimumSize
</enum>
</property>
<item>
<layout
class=
"QVBoxLayout"
name=
"firstVerticalLayout"
>
<layout
class=
"QVBoxLayout"
name=
"firstVerticalLayout"
stretch=
"1,1,0,3"
>
<item>
<widget
class=
"KCalcDisplay"
name=
"calc_display"
>
<property
name=
"sizePolicy"
>
<sizepolicy
hsizetype=
"MinimumExpanding"
vsizetype=
"
Fixed
"
>
<sizepolicy
hsizetype=
"MinimumExpanding"
vsizetype=
"
MinimumExpanding
"
>
<horstretch>
0
</horstretch>
<verstretch>
0
</verstretch>
</sizepolicy>
...
...
kcalcdisplay.cpp
View file @
6c3b4763
...
...
@@ -598,6 +598,26 @@ void KCalcDisplay::setText(const QString &string)
Q_EMIT
changedText
(
text_
);
}
//------------------------------------------------------------------------------
// Name: setFont
// Desc: Set the font and recalculate the font size to better fit
//------------------------------------------------------------------------------
void
KCalcDisplay
::
setFont
(
const
QFont
&
font
)
{
// Make a copy of the font
QFont
*
newFont
=
new
QFont
(
font
);
// Calculate ideal font size
// constant arbitrarily chosen, adjust/increase if scaling issues arise
newFont
->
setPointSizeF
(
qMax
(
double
(
font
.
pointSize
()),
contentsRect
().
height
()
/
3.6
));
// Apply font
QFrame
::
setFont
(
*
newFont
);
// Free the memory
delete
newFont
;
}
//------------------------------------------------------------------------------
// Name: formatDecimalNumber
// Desc: Convert decimal number to locale-dependent format.
...
...
@@ -1025,7 +1045,7 @@ void KCalcDisplay::paintEvent(QPaintEvent *)
// draw the status texts using half of the normal
// font size but not smaller than 7pt
QFont
fnt
(
font
());
fnt
.
setPointSize
(
qMax
((
fnt
.
pointSize
()
/
2
),
7
));
fnt
.
setPointSize
F
(
qMax
((
fnt
.
pointSize
()
/
2
.0
),
7
.0
));
painter
.
setFont
(
fnt
);
QFontMetrics
fm
(
fnt
);
...
...
@@ -1037,6 +1057,18 @@ void KCalcDisplay::paintEvent(QPaintEvent *)
}
}
//------------------------------------------------------------------------------
// Name: resizeEvent
// Desc: resize display and adjust font size
//------------------------------------------------------------------------------
void
KCalcDisplay
::
resizeEvent
(
QResizeEvent
*
event
)
{
QFrame
::
resizeEvent
(
event
);
// Set font again (forcing size recalculation)
setFont
(
KCalcSettings
::
displayFont
());
}
//------------------------------------------------------------------------------
// Name: sizeHint
// Desc:
...
...
kcalcdisplay.h
View file @
6c3b4763
...
...
@@ -65,6 +65,7 @@ public:
void
setFixedPrecision
(
int
precision
);
void
setPrecision
(
int
precision
);
void
setText
(
const
QString
&
string
);
void
setFont
(
const
QFont
&
font
);
QString
formatDecimalNumber
(
QString
string
);
QString
groupDigits
(
const
QString
&
displayString
,
int
numDigits
);
QString
text
()
const
;
...
...
@@ -89,6 +90,7 @@ Q_SIGNALS:
protected:
void
mousePressEvent
(
QMouseEvent
*
)
override
;
void
paintEvent
(
QPaintEvent
*
p
)
override
;
void
resizeEvent
(
QResizeEvent
*
event
)
override
;
private:
bool
changeSign
();
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment