Commit f4fbc98b authored by Ryan McCoskrie's avatar Ryan McCoskrie Committed by Nate Graham
Browse files

Add support for resizing by dragging the title bar

Summary:
This is for the benefit of users who find changing the window height
through the configuration window overly tedious.

This may cause slight flickering during resizing.

FEATURE: 154686
FIXED-IN: 20.04.0

Test Plan:
Run patched Yakuake.
Drag Titlebar up and down the screen.

Yakuake should automatically update its height configuration while being dragged.

Reviewers: #yakuake, hein, mweepigeon, ngraham

Reviewed By: mweepigeon, ngraham

Subscribers: mweepigeon, ngraham

Tags: #yakuake

Differential Revision: https://phabricator.kde.org/D22227
parent aa5306c4
/*
Copyright (C) 2008-2014 by Eike Hein <hein@kde.org>
Copyright (C) 2009 by Juan Carlos Torres <carlosdgtorres@gmail.com>
Copyright (C) 2020 by Ryan McCoskrie <work@ryanmccoskrie.me>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
......
......@@ -54,6 +54,8 @@ class MainWindow : public KMainWindow
Q_OBJECT
Q_CLASSINFO("D-Bus Interface", "org.kde.yakuake")
friend class TitleBar;
public:
explicit MainWindow(QWidget* parent = 0);
~MainWindow();
......
/*
Copyright (C) 2008-2014 by Eike Hein <hein@kde.org>
Copyright (C) 2020 by Ryan McCoskrie <work@ryanmccoskrie.me>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
......@@ -43,11 +44,14 @@ TitleBar::TitleBar(MainWindow* mainWindow) : QWidget(mainWindow)
m_mainWindow = mainWindow;
m_skin = mainWindow->skin();
setCursor(Qt::SizeVerCursor);
m_focusButton = new QPushButton(this);
m_focusButton->setFocusPolicy(Qt::NoFocus);
m_focusButton->setCheckable(true);
m_focusButton->setToolTip(xi18nc("@info:tooltip", "Keep window open when it loses focus"));
m_focusButton->setWhatsThis(xi18nc("@info:whatsthis", "If this is checked, the window will stay open when it loses focus."));
m_focusButton->setCursor(Qt::ArrowCursor);
connect(m_focusButton, SIGNAL(toggled(bool)), mainWindow, SLOT(setKeepOpen(bool)));
m_menuButton = new QPushButton(this);
......@@ -55,11 +59,13 @@ TitleBar::TitleBar(MainWindow* mainWindow) : QWidget(mainWindow)
m_menuButton->setMenu(mainWindow->menu());
m_menuButton->setToolTip(xi18nc("@info:tooltip", "Open Menu"));
m_menuButton->setWhatsThis(xi18nc("@info:whatsthis", "Opens the main menu."));
m_menuButton->setCursor(Qt::ArrowCursor);
m_quitButton = new QPushButton(this);
m_quitButton->setFocusPolicy(Qt::NoFocus);
m_quitButton->setToolTip(xi18nc("@info:tooltip Quits the application", "Quit"));
m_quitButton->setWhatsThis(xi18nc("@info:whatsthis", "Quits the application."));
m_quitButton->setCursor(Qt::ArrowCursor);
connect(m_quitButton, SIGNAL(clicked()), mainWindow, SLOT(close()));
}
......@@ -138,6 +144,29 @@ void TitleBar::paintEvent(QPaintEvent*)
painter.end();
}
void TitleBar::mouseMoveEvent(QMouseEvent* event)
{
if(event->buttons() == Qt::LeftButton) {
//Dynamic cast needed to use getDesktopGeometry()
MainWindow* window = dynamic_cast<MainWindow*>( parent() );
int maxHeight = window->getDesktopGeometry().height();
int newHeight = event->globalY() / (maxHeight / 100);
//Correct newHeight if mouse is dragged too far
if(newHeight > 100) {
newHeight = 100;
}
else if(newHeight < 10) {
newHeight = 10;
}
window->setWindowHeight(newHeight);
} else {
QWidget::mouseMoveEvent(event);
}
}
void TitleBar::updateMask()
{
const QPixmap& leftCornerImage = m_skin->titleBarLeftCornerImage();
......
/*
Copyright (C) 2008-2014 by Eike Hein <hein@kde.org>
Copyright (C) 2020 by Ryan McCoskrie <work@ryanmccoskrie.me>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
......@@ -24,6 +25,7 @@
#include <QWidget>
#include <QMouseEvent>
class MainWindow;
......@@ -55,6 +57,7 @@ class TitleBar : public QWidget
protected:
void resizeEvent(QResizeEvent*) override;
void paintEvent(QPaintEvent*) override;
void mouseMoveEvent(QMouseEvent*) override;
private:
......
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