Commit 66e19aaf authored by Luis Javier Merino's avatar Luis Javier Merino Committed by Tomaz Canabrava
Browse files

De-qwidget-ize TerminalColor and TerminalFonts

Something was swallowing mouse moves on the top left 100x30 pixels of
TerminalDisplay.  As it turns out, it was the widgets for TerminalFonts
and TerminalColor.  Neither of them really needs to be a QWidget.

TerminalColor emits the onPalette(const QPalette &) signal, has slots,
and overrides event(QEvent &), so turn it into a QObject.

TerminalFonts doesn't do any of the above, turn it into a plain C++
object.

Now that TerminalFonts is no longer a QObject, manage it with a
std::unique_ptr.

TerminalFonts::fontChange(const QFont &) was calling update(), which was
probably a leftover from when it was split from TerminalDisplay.  Get
rid of it.  Trivial testing using keyboard shortcuts to change font size
(Ctrl++, Ctrl+-, Alt+Ctrl+0), and previewing font changes on "Edit
Current Profile..." seem to indicate that it isn't needed.
parent b5d17438
......@@ -20,8 +20,8 @@
namespace Konsole
{
TerminalColor::TerminalColor(QWidget *parent)
: QWidget(parent)
TerminalColor::TerminalColor(QObject *parent)
: QObject(parent)
, m_opacity(1.0)
, m_blendColor(qRgba(0, 0, 0, 0xff))
, m_cursorColor(QColor())
......@@ -112,7 +112,7 @@ namespace Konsole
default:
break;
}
return QWidget::event(event);
return QObject::event(event);
}
void TerminalColor::onColorsChanged()
......
......@@ -24,11 +24,11 @@ namespace Konsole
class Profile;
class ColorScheme;
class KONSOLEPRIVATE_EXPORT TerminalColor : public QWidget
class KONSOLEPRIVATE_EXPORT TerminalColor : public QObject
{
Q_OBJECT
public:
explicit TerminalColor(QWidget *parent);
explicit TerminalColor(QObject *parent);
void applyProfile(const Profile::Ptr &profile, ColorScheme const *colorScheme, uint randomSeed);
......
......@@ -243,6 +243,7 @@ TerminalDisplay::TerminalDisplay(QWidget* parent)
, _drawOverlay(false)
, _scrollBar(nullptr)
, _terminalColor(nullptr)
, _terminalFont(std::make_unique<TerminalFont>(this))
{
// terminal applications are not designed with Right-To-Left in mind,
// so the layout is forced to Left-To-Right
......@@ -317,8 +318,6 @@ TerminalDisplay::TerminalDisplay(QWidget* parent)
_terminalColor = new TerminalColor(this);
connect(_terminalColor, &TerminalColor::onPalette, _scrollBar, &TerminalScrollBar::setPalette);
_terminalFont = new TerminalFont(this);
_terminalPainter = new TerminalPainter(this);
connect(this, &TerminalDisplay::drawContents, _terminalPainter, &TerminalPainter::drawContents);
connect(this, &TerminalDisplay::drawCurrentResultRect, _terminalPainter, &TerminalPainter::drawCurrentResultRect);
......
......@@ -299,7 +299,7 @@ public:
TerminalFont *terminalFont() const
{
return _terminalFont;
return _terminalFont.get();
}
bool cursorBlinking() const
......@@ -746,7 +746,7 @@ private:
TerminalPainter *_terminalPainter;
TerminalScrollBar *_scrollBar;
TerminalColor *_terminalColor;
TerminalFont *_terminalFont;
std::unique_ptr<TerminalFont> _terminalFont;
std::unique_ptr<KonsolePrintManager> _printManager;
};
......
......@@ -23,7 +23,7 @@
namespace Konsole
{
TerminalFont::TerminalFont(QWidget *parent)
: QWidget(parent)
: m_parent(parent)
, m_lineSpacing(0)
, m_fontHeight(1)
, m_fontWidth(1)
......@@ -90,7 +90,7 @@ namespace Konsole
// italic, etc) are stored in QFont independently, in almost all cases styleName is not needed.
newFont.setStyleName(QString());
if (newFont == qobject_cast<QWidget*>(parent())->font()) {
if (newFont == qobject_cast<QWidget*>(m_parent)->font()) {
// Do not process the same font again
return;
}
......@@ -124,18 +124,18 @@ namespace Konsole
qCDebug(KonsoleDebug) << " System : " << nonMatching;
}
qobject_cast<QWidget*>(parent())->setFont(newFont);
qobject_cast<QWidget*>(m_parent)->setFont(newFont);
fontChange(newFont);
}
QFont TerminalFont::getVTFont() const
{
return qobject_cast<QWidget*>(parent())->font();
return qobject_cast<QWidget*>(m_parent)->font();
}
void TerminalFont::increaseFontSize()
{
QFont font = qobject_cast<QWidget*>(parent())->font();
QFont font = qobject_cast<QWidget*>(m_parent)->font();
font.setPointSizeF(font.pointSizeF() + 1);
setVTFont(font);
}
......@@ -144,7 +144,7 @@ namespace Konsole
{
const qreal MinimumFontSize = 6;
QFont font = qobject_cast<QWidget*>(parent())->font();
QFont font = qobject_cast<QWidget*>(m_parent)->font();
font.setPointSizeF(qMax(font.pointSizeF() - 1, MinimumFontSize));
setVTFont(font);
}
......@@ -153,7 +153,7 @@ namespace Konsole
{
const qreal MinimumFontSize = 6;
TerminalDisplay *display = qobject_cast<TerminalDisplay*>(parent());
TerminalDisplay *display = qobject_cast<TerminalDisplay*>(m_parent);
QFont font = display->font();
Profile::Ptr currentProfile = SessionManager::instance()->sessionProfile(display->sessionController()->session());
const qreal defaultFontSize = currentProfile->font().pointSizeF();
......@@ -164,7 +164,7 @@ namespace Konsole
void TerminalFont::setLineSpacing(uint i)
{
m_lineSpacing = i;
fontChange(qobject_cast<QWidget*>(parent())->font());
fontChange(qobject_cast<QWidget*>(m_parent)->font());
}
uint TerminalFont::lineSpacing() const
......@@ -204,7 +204,7 @@ namespace Konsole
void TerminalFont::fontChange(const QFont &)
{
QFontMetrics fm(qobject_cast<QWidget*>(parent())->font());
QFontMetrics fm(qobject_cast<QWidget*>(m_parent)->font());
m_fontHeight = fm.height() + m_lineSpacing;
Q_ASSERT(m_fontHeight > 0);
......@@ -217,8 +217,7 @@ namespace Konsole
m_fontAscent = fm.ascent();
qobject_cast<TerminalDisplay*>(parent())->propagateSize();
update();
qobject_cast<TerminalDisplay*>(m_parent)->propagateSize();
}
}
......@@ -18,9 +18,8 @@ class QFont;
namespace Konsole
{
class TerminalFont : public QWidget
class TerminalFont
{
Q_OBJECT
public:
explicit TerminalFont(QWidget *parent = nullptr);
~TerminalFont() = default;
......@@ -48,6 +47,7 @@ namespace Konsole
void fontChange(const QFont &);
private:
QWidget *m_parent;
uint m_lineSpacing;
int m_fontHeight;
int m_fontWidth;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment