Skip to content
GitLab
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
0eb1008f
Commit
0eb1008f
authored
Sep 10, 2021
by
Niklas Freund
Browse files
Fixed several resizing issues
parent
6c3b4763
Changes
3
Hide whitespace changes
Inline
Side-by-side
kcalc.cpp
View file @
0eb1008f
...
...
@@ -690,6 +690,7 @@ void KCalculator::updateGeometry()
for
(
QObject
*
obj
:
leftPadList
)
{
if
(
auto
const
button
=
qobject_cast
<
KCalcButton
*>
(
obj
))
{
button
->
setMinimumWidth
(
em
.
width
()
*
4
+
margin
*
2
);
button
->
setMinimumHeight
(
em
.
height
()
*
1.25
+
margin
*
2
);
button
->
installEventFilter
(
this
);
}
}
...
...
@@ -699,6 +700,7 @@ void KCalculator::updateGeometry()
for
(
QObject
*
obj
:
rightPadList
)
{
if
(
auto
const
button
=
qobject_cast
<
KCalcButton
*>
(
obj
))
{
button
->
setMinimumWidth
(
em
.
width
()
*
3
+
margin
*
2
);
button
->
setMinimumHeight
(
em
.
height
()
*
1.25
+
margin
*
2
);
button
->
installEventFilter
(
this
);
}
}
...
...
@@ -708,6 +710,7 @@ void KCalculator::updateGeometry()
for
(
QObject
*
obj
:
numericPadList
)
{
if
(
auto
const
button
=
qobject_cast
<
KCalcButton
*>
(
obj
))
{
button
->
setMinimumWidth
(
em
.
width
()
*
3
+
margin
*
2
);
button
->
setMinimumHeight
(
em
.
height
()
*
1.25
+
margin
*
2
);
button
->
installEventFilter
(
this
);
}
}
...
...
@@ -1896,6 +1899,10 @@ void KCalculator::slotSetSimpleMode()
QSizePolicy
policy
=
leftPad
->
sizePolicy
();
policy
.
setHorizontalStretch
(
0
);
leftPad
->
setSizePolicy
(
policy
);
// update font size
QApplication
::
processEvents
();
setFonts
();
}
//------------------------------------------------------------------------------
...
...
@@ -1939,6 +1946,10 @@ void KCalculator::slotSetScienceMode()
QSizePolicy
policy
=
leftPad
->
sizePolicy
();
policy
.
setHorizontalStretch
(
1
);
leftPad
->
setSizePolicy
(
policy
);
// update font size
QApplication
::
processEvents
();
setFonts
();
}
//------------------------------------------------------------------------------
...
...
@@ -1982,6 +1993,10 @@ void KCalculator::slotSetStatisticMode()
QSizePolicy
policy
=
leftPad
->
sizePolicy
();
policy
.
setHorizontalStretch
(
1
);
leftPad
->
setSizePolicy
(
policy
);
// update font size
QApplication
::
processEvents
();
setFonts
();
}
//------------------------------------------------------------------------------
...
...
@@ -2023,6 +2038,10 @@ void KCalculator::slotSetNumeralMode()
QSizePolicy
policy
=
leftPad
->
sizePolicy
();
policy
.
setHorizontalStretch
(
1
);
leftPad
->
setSizePolicy
(
policy
);
// update font size
QApplication
::
processEvents
();
setFonts
();
}
//------------------------------------------------------------------------------
...
...
@@ -2474,8 +2493,6 @@ void KCalculator::setFonts()
button
->
setFont
(
buttonFont
);
}
}
updateGeometry
();
}
//------------------------------------------------------------------------------
...
...
@@ -2487,6 +2504,7 @@ bool KCalculator::event(QEvent *e)
switch
(
e
->
type
())
{
case
QEvent
::
ApplicationFontChange
:
setFonts
();
updateGeometry
();
break
;
case
QEvent
::
ApplicationPaletteChange
:
setColors
();
...
...
@@ -2615,6 +2633,8 @@ void KCalculator::resizeEvent(QResizeEvent* event)
KXmlGuiWindow
::
resizeEvent
(
event
);
// If the content size is now larger than the window size, resize window to fit
// (Workaround for bug where changing from simple to science mode in maximized state
// and then restoring results in the window being too small for content)
QSize
contentSize
=
firstVerticalLayout
->
contentsRect
().
size
();
QMargins
contentMargins
=
KCalculator
::
contentsMargins
();
QSize
windowSize
=
KCalculator
::
frameSize
();
...
...
kcalcdisplay.cpp
View file @
0eb1008f
...
...
@@ -38,6 +38,8 @@ KCalcDisplay::KCalcDisplay(QWidget *parent)
,
history_index_
(
0
)
,
selection_timer_
(
new
QTimer
(
this
))
{
baseFont_
=
nullptr
;
setFocusPolicy
(
Qt
::
StrongFocus
);
setSizePolicy
(
QSizePolicy
(
QSizePolicy
::
Expanding
,
QSizePolicy
::
Fixed
));
...
...
@@ -600,16 +602,31 @@ void KCalcDisplay::setText(const QString &string)
//------------------------------------------------------------------------------
// Name: setFont
// Desc: Set the font and recalculate the font size to better fit
// Desc: Set the
base
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
);
// Overwrite current baseFont
if
(
baseFont_
)
{
delete
baseFont_
;
}
baseFont_
=
new
QFont
(
font
);
updateFont
();
}
//------------------------------------------------------------------------------
// Name: updateFont
// Desc: Update font using baseFont to better fit
//------------------------------------------------------------------------------
void
KCalcDisplay
::
updateFont
()
{
// Make a working copy of the font
QFont
*
newFont
=
new
QFont
(
baseFont
());
// Calculate ideal font size
// constant arbitrarily chosen, adjust/increase if scaling issues arise
newFont
->
setPointSizeF
(
qMax
(
double
(
f
ont
.
pointSize
()),
contentsRect
().
height
()
/
3.6
));
newFont
->
setPointSizeF
(
qMax
(
double
(
baseF
ont
()
.
pointSize
()),
contentsRect
().
height
()
/
3.6
));
// Apply font
QFrame
::
setFont
(
*
newFont
);
...
...
@@ -618,6 +635,15 @@ void KCalcDisplay::setFont(const QFont &font)
delete
newFont
;
}
//------------------------------------------------------------------------------
// Name: baseFont
// Desc:
//------------------------------------------------------------------------------
const
QFont
&
KCalcDisplay
::
baseFont
()
const
{
return
*
baseFont_
;
}
//------------------------------------------------------------------------------
// Name: formatDecimalNumber
// Desc: Convert decimal number to locale-dependent format.
...
...
@@ -1065,8 +1091,8 @@ void KCalcDisplay::resizeEvent(QResizeEvent* event)
{
QFrame
::
resizeEvent
(
event
);
//
Set font again (forcing size recalculation)
setFont
(
KCalcSettings
::
display
Font
()
)
;
//
Update font size
update
Font
();
}
//------------------------------------------------------------------------------
...
...
@@ -1075,11 +1101,14 @@ void KCalcDisplay::resizeEvent(QResizeEvent* event)
//------------------------------------------------------------------------------
QSize
KCalcDisplay
::
sizeHint
()
const
{
// font metrics of base font
const
QFontMetrics
fmBase
(
baseFont
());
// basic size
QSize
sz
=
f
ontMetrics
()
.
size
(
Qt
::
TextSingleLine
,
text_
);
QSize
sz
=
f
mBase
.
size
(
Qt
::
TextSingleLine
,
text_
);
// expanded by 3/4 font height to make room for the status texts
QFont
fnt
(
f
ont
());
QFont
fnt
(
baseF
ont
());
fnt
.
setPointSize
(
qMax
(((
fnt
.
pointSize
()
*
3
)
/
4
),
7
));
const
QFontMetrics
fm
(
fnt
);
...
...
kcalcdisplay.h
View file @
0eb1008f
...
...
@@ -66,6 +66,8 @@ public:
void
setPrecision
(
int
precision
);
void
setText
(
const
QString
&
string
);
void
setFont
(
const
QFont
&
font
);
void
updateFont
();
const
QFont
&
baseFont
()
const
;
QString
formatDecimalNumber
(
QString
string
);
QString
groupDigits
(
const
QString
&
displayString
,
int
numDigits
);
QString
text
()
const
;
...
...
@@ -119,6 +121,8 @@ private:
int
fixed_precision_
;
// "-1" = no fixed_precision
KNumber
display_amount_
;
QFont
*
baseFont_
;
QVector
<
KNumber
>
history_list_
;
int
history_index_
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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