Commit 1f8e9fbc authored by Lionel Chauvin's avatar Lionel Chauvin Committed by Nate Graham
Browse files

[Yakuake] Improve customization

Summary:
This patch increases Yakuake customization possibilities without break existing skins.
The new features are:
- new tab button can be positionned at the end of tabs
- selected tab text can be not bold
- titlebar's title can be centered
- titlebar's icons can be anchored at left
- a compact mode that superposes title and tabbar

Here examples of what can be achieved with these changes:

{F6698444}

{F6711610}

Test Plan:
Install skins:

{F6711608}
{F6711609}

Reviewers: hein, #yakuake

Reviewed By: hein

Tags: #yakuake

Differential Revision: https://phabricator.kde.org/D19835
parent ba755994
......@@ -84,8 +84,9 @@ MainWindow::MainWindow(QWidget* parent)
m_menu = new QMenu(this);
m_helpMenu = new KHelpMenu(this, KAboutData::applicationData());
m_sessionStack = new SessionStack(this);
m_tabBar = new TabBar(this);
m_titleBar = new TitleBar(this);
m_tabBar = new TabBar(this);
m_firstRunDialog = NULL;
m_isFullscreen = false;
......@@ -649,6 +650,9 @@ void MainWindow::setupMenu()
m_menu->addAction(actionCollection()->action(QLatin1String(KStandardAction::name(KStandardAction::KeyBindings))));
m_menu->addAction(actionCollection()->action(QLatin1String(KStandardAction::name(KStandardAction::ConfigureNotifications))));
m_menu->addAction(actionCollection()->action(QLatin1String(KStandardAction::name(KStandardAction::Preferences))));
m_menu->addSeparator();
m_menu->addAction(actionCollection()->action(QLatin1String(KStandardAction::name(KStandardAction::Quit))));
}
void MainWindow::updateScreenMenu()
......@@ -894,9 +898,17 @@ void MainWindow::setWindowGeometry(int newWidth, int newHeight, int newPosition)
if (Settings::showTabBar())
{
maxHeight -= m_tabBar->height();
m_tabBar->setGeometry(m_skin->borderWidth(), maxHeight,
width() - 2 * m_skin->borderWidth(), m_tabBar->height());
if (m_skin->tabBarCompact())
{
m_tabBar->setGeometry(m_skin->tabBarLeft(), maxHeight,
width() - m_skin->tabBarLeft() - m_skin->tabBarRight(), m_tabBar->height());
}
else
{
maxHeight -= m_tabBar->height();
m_tabBar->setGeometry(m_skin->borderWidth(), maxHeight,
width() - 2 * m_skin->borderWidth(), m_tabBar->height());
}
}
m_sessionStack->setGeometry(m_skin->borderWidth(), 0,
......
......@@ -83,6 +83,8 @@ bool Skin::load(const QString& name, bool kns)
titleDir + titleBarFocusButton.readEntry("over_image", ""),
titleDir + titleBarFocusButton.readEntry("down_image", ""));
m_titleBarFocusButtonAnchor = titleBarFocusButton.readEntry("anchor", "") == QStringLiteral("left") ? Qt::AnchorLeft : Qt::AnchorRight;
KConfigGroup titleBarMenuButton = titleConfig.group("ConfigButton");
......@@ -93,6 +95,8 @@ bool Skin::load(const QString& name, bool kns)
titleDir + titleBarMenuButton.readEntry("over_image", ""),
titleDir + titleBarMenuButton.readEntry("down_image", ""));
m_titleBarMenuButtonAnchor = titleBarMenuButton.readEntry("anchor", "") == QStringLiteral("left") ? Qt::AnchorLeft : Qt::AnchorRight;
KConfigGroup titleBarQuitButton = titleConfig.group("QuitButton");
......@@ -103,6 +107,8 @@ bool Skin::load(const QString& name, bool kns)
titleDir + titleBarQuitButton.readEntry("over_image", ""),
titleDir + titleBarQuitButton.readEntry("down_image", ""));
m_titleBarQuitButtonAnchor = titleBarQuitButton.readEntry("anchor", "") == QStringLiteral("left") ? Qt::AnchorLeft : Qt::AnchorRight;
KConfigGroup titleBarText = titleConfig.group("Text");
......@@ -116,6 +122,7 @@ bool Skin::load(const QString& name, bool kns)
titleBarText.readEntry("blue", 0));
m_titleBarTextBold = titleBarText.readEntry("bold", true);
m_titleBarTextCentered = titleBarText.readEntry("centered", false);
KConfigGroup tabBar = tabConfig.group("Tabs");
......@@ -134,11 +141,13 @@ bool Skin::load(const QString& name, bool kns)
m_tabBarUnselectedRightCornerImage.load(tabDir + tabBar.readEntry("unselected_right_corner", ""));
m_tabBarSelectedLeftCornerImage.load(tabDir + tabBar.readEntry("selected_left_corner", ""));
m_tabBarSelectedRightCornerImage.load(tabDir + tabBar.readEntry("selected_right_corner", ""));
m_tabBarSelectedTextBold = tabBar.readEntry("selected_text_bold", true);
m_tabBarPreventClosingImage.load(tabDir + tabBar.readEntry("prevent_closing_image", ""));
m_tabBarPreventClosingImagePosition.setX(tabBar.readEntry("prevent_closing_image_x", 0));
m_tabBarPreventClosingImagePosition.setY(tabBar.readEntry("prevent_closing_image_y", 0));
m_tabBarCompact = tabBar.readEntry("compact", false);
KConfigGroup tabBarBackground = tabConfig.group("Background");
......@@ -156,6 +165,8 @@ bool Skin::load(const QString& name, bool kns)
tabDir + tabBarNewTabButton.readEntry("over_image", ""),
tabDir + tabBarNewTabButton.readEntry("down_image", ""));
m_tabBarNewTabButtonIsAtEndOfTabs = tabBarNewTabButton.readEntry("at_end_of_tabs", false);
KConfigGroup tabBarCloseTabButton = tabConfig.group("MinusButton");
......@@ -166,6 +177,29 @@ bool Skin::load(const QString& name, bool kns)
tabDir + tabBarCloseTabButton.readEntry("over_image", ""),
tabDir + tabBarCloseTabButton.readEntry("down_image", ""));
if (m_tabBarCompact)
{
if (m_tabBarNewTabButtonIsAtEndOfTabs)
{
m_tabBarLeft = m_tabBarPosition.x();
m_tabBarPosition.setX(0);
}
else
{
if (m_tabBarNewTabButtonPosition.x() < m_tabBarPosition.x())
m_tabBarLeft = m_tabBarNewTabButtonPosition.x();
else
m_tabBarLeft = m_tabBarPosition.x();
m_tabBarPosition.setX(m_tabBarPosition.x() - m_tabBarLeft);
m_tabBarNewTabButtonPosition.setX(m_tabBarNewTabButtonPosition.x() - m_tabBarLeft);
}
int closeButtonWidth = QPixmap(tabDir + tabBarCloseTabButton.readEntry("up_image", "")).width();
m_tabBarRight = m_tabBarCloseTabButtonPosition.x() - closeButtonWidth;
m_tabBarCloseTabButtonPosition.setX(closeButtonWidth);
}
if (m_tabBarPreventClosingImage.isNull())
updateTabBarPreventClosingImageCache();
......
......@@ -48,19 +48,22 @@ class Skin : public QObject
const QPixmap& titleBarRightCornerImage() { return m_titleBarRightCornerImage; }
const QPoint& titleBarFocusButtonPosition() { return m_titleBarFocusButtonPosition; }
const Qt::AnchorPoint& titleBarFocusButtonAnchor() { return m_titleBarFocusButtonAnchor; }
const QString titleBarFocusButtonStyleSheet() { return m_titleBarFocusButtonStyleSheet; }
const QPoint& titleBarMenuButtonPosition() { return m_titleBarMenuButtonPosition; }
const Qt::AnchorPoint& titleBarMenuButtonAnchor() { return m_titleBarMenuButtonAnchor; }
const QString titleBarMenuButtonStyleSheet() { return m_titleBarMenuButtonStyleSheet; }
const QPoint& titleBarQuitButtonPosition() { return m_titleBarQuitButtonPosition; }
const Qt::AnchorPoint& titleBarQuitButtonAnchor() { return m_titleBarQuitButtonAnchor; }
const QString titleBarQuitButtonStyleSheet() { return m_titleBarQuitButtonStyleSheet; }
const QString titleBarText() { return m_titleBarText; }
const QPoint& titleBarTextPosition() { return m_titleBarTextPosition; }
const QColor& titleBarTextColor() { return m_titleBarTextColor; }
bool titleBarTextBold() { return m_titleBarTextBold; }
bool titleBarTextBold() { return m_titleBarTextBold; }
bool titleBarTextCentered() { return m_titleBarTextCentered; }
const QPoint& tabBarPosition() { return m_tabBarPosition; }
const QColor& tabBarTextColor() { return m_tabBarTextColor; }
......@@ -72,6 +75,11 @@ class Skin : public QObject
const QPixmap& tabBarUnselectedRightCornerImage() { return m_tabBarUnselectedRightCornerImage; }
const QPixmap& tabBarSelectedLeftCornerImage() { return m_tabBarSelectedLeftCornerImage; }
const QPixmap& tabBarSelectedRightCornerImage() { return m_tabBarSelectedRightCornerImage; }
bool tabBarSelectedTextBold() { return m_tabBarSelectedTextBold; }
bool tabBarCompact() { return m_tabBarCompact; }
int tabBarLeft() { return m_tabBarLeft; }
int tabBarRight() { return m_tabBarRight; }
const QPixmap tabBarPreventClosingImage();
const QPoint& tabBarPreventClosingImagePosition() { return m_tabBarPreventClosingImagePosition; }
......@@ -82,11 +90,11 @@ class Skin : public QObject
const QPoint& tabBarNewTabButtonPosition() { return m_tabBarNewTabButtonPosition; }
const QString tabBarNewTabButtonStyleSheet() { return m_tabBarNewTabButtonStyleSheet; }
bool tabBarNewTabButtonIsAtEndOfTabs() { return m_tabBarNewTabButtonIsAtEndOfTabs; }
const QPoint& tabBarCloseTabButtonPosition() { return m_tabBarCloseTabButtonPosition; }
const QString tabBarCloseTabButtonStyleSheet() { return m_tabBarCloseTabButtonStyleSheet; }
Q_SIGNALS:
void iconChanged();
......@@ -109,18 +117,22 @@ class Skin : public QObject
QPixmap m_titleBarRightCornerImage;
QPoint m_titleBarFocusButtonPosition;
Qt::AnchorPoint m_titleBarFocusButtonAnchor;
QString m_titleBarFocusButtonStyleSheet;
QPoint m_titleBarMenuButtonPosition;
Qt::AnchorPoint m_titleBarMenuButtonAnchor;
QString m_titleBarMenuButtonStyleSheet;
QPoint m_titleBarQuitButtonPosition;
Qt::AnchorPoint m_titleBarQuitButtonAnchor;
QString m_titleBarQuitButtonStyleSheet;
QString m_titleBarText;
QPoint m_titleBarTextPosition;
QColor m_titleBarTextColor;
bool m_titleBarTextBold;
bool m_titleBarTextCentered;
QPoint m_tabBarPosition;
QColor m_tabBarTextColor;
......@@ -132,6 +144,7 @@ class Skin : public QObject
QPixmap m_tabBarUnselectedRightCornerImage;
QPixmap m_tabBarSelectedLeftCornerImage;
QPixmap m_tabBarSelectedRightCornerImage;
bool m_tabBarSelectedTextBold;
QPixmap m_tabBarPreventClosingImage;
QPixmap m_tabBarPreventClosingImageCached;
......@@ -143,6 +156,11 @@ class Skin : public QObject
QPoint m_tabBarNewTabButtonPosition;
QString m_tabBarNewTabButtonStyleSheet;
bool m_tabBarNewTabButtonIsAtEndOfTabs;
bool m_tabBarCompact;
int m_tabBarLeft;
int m_tabBarRight;
QPoint m_tabBarCloseTabButtonPosition;
QString m_tabBarCloseTabButtonStyleSheet;
......
......@@ -115,9 +115,8 @@ void TabBar::applySkin()
m_newTabButton->setStyleSheet(m_skin->tabBarNewTabButtonStyleSheet());
m_closeTabButton->setStyleSheet(m_skin->tabBarCloseTabButtonStyleSheet());
m_newTabButton->move( m_skin->tabBarNewTabButtonPosition().x(), m_skin->tabBarNewTabButtonPosition().y());
moveNewTabButton();
m_closeTabButton->move(width() - m_skin->tabBarCloseTabButtonPosition().x(), m_skin->tabBarCloseTabButtonPosition().y());
repaint();
}
......@@ -395,12 +394,20 @@ void TabBar::contextMenuEvent(QContextMenuEvent* event)
void TabBar::resizeEvent(QResizeEvent* event)
{
m_newTabButton->move(m_skin->tabBarNewTabButtonPosition().x(), m_skin->tabBarNewTabButtonPosition().y());
moveNewTabButton();
m_closeTabButton->move(width() - m_skin->tabBarCloseTabButtonPosition().x(), m_skin->tabBarCloseTabButtonPosition().y());
QWidget::resizeEvent(event);
}
void TabBar::moveNewTabButton()
{
int newTabButtonX = m_skin->tabBarNewTabButtonPosition().x();
if (m_skin->tabBarNewTabButtonIsAtEndOfTabs()) {
newTabButtonX += m_tabWidths.last();
}
m_newTabButton->move(newTabButtonX, m_skin->tabBarNewTabButtonPosition().y());
}
void TabBar::paintEvent(QPaintEvent*)
{
QPainter painter(this);
......@@ -415,7 +422,7 @@ void TabBar::paintEvent(QPaintEvent*)
for (int index = 0; index < m_tabs.count(); ++index)
{
x = drawButton(x, y, index, painter);
x = drawTab(x, y, index, painter);
m_tabWidths << x;
}
......@@ -446,9 +453,13 @@ void TabBar::paintEvent(QPaintEvent*)
painter.drawTiledPixmap(0, 0, width(), height(), backgroundImage);
painter.end();
if (m_skin->tabBarNewTabButtonIsAtEndOfTabs()) {
moveNewTabButton();
}
}
int TabBar::drawButton(int x, int y, int index, QPainter& painter)
int TabBar::drawTab(int x, int y, int index, QPainter& painter)
{
QString title;
int sessionId;
......@@ -476,7 +487,7 @@ int TabBar::drawButton(int x, int y, int index, QPainter& painter)
x += m_skin->tabBarSeparatorImage().width();
}
if (selected) font.setBold(true);
if (selected) font.setBold(m_skin->tabBarSelectedTextBold());
else font.setBold(false);
painter.setFont(font);
......@@ -990,7 +1001,7 @@ void TabBar::startDrag(int index)
painter.initFrom(this);
painter.setPen(m_skin->tabBarTextColor());
drawButton(0, 0, index, painter);
drawTab(0, 0, index, painter);
painter.end();
QMimeData* mimeData = new QMimeData;
......
......@@ -122,7 +122,8 @@ class TabBar : public QWidget
void updateToggleMonitorSilenceMenu(int sessionId = -1);
void updateToggleMonitorActivityMenu(int sessionId = -1);
int drawButton(int x, int y, int index, QPainter& painter);
int drawTab(int x, int y, int index, QPainter& painter);
void moveNewTabButton();
void startDrag(int index);
void drawDropIndicator(int index, bool disabled = false);
......
......@@ -32,7 +32,6 @@
#include <QBitmap>
#include <QPainter>
TitleBar::TitleBar(MainWindow* mainWindow) : QWidget(mainWindow)
{
setWhatsThis(xi18nc("@info:whatsthis",
......@@ -76,20 +75,34 @@ void TitleBar::applySkin()
m_menuButton->setStyleSheet(m_skin->titleBarMenuButtonStyleSheet());
m_quitButton->setStyleSheet(m_skin->titleBarQuitButtonStyleSheet());
m_focusButton->move(width() - m_skin->titleBarFocusButtonPosition().x(), m_skin->titleBarFocusButtonPosition().y());
m_menuButton->move(width() - m_skin->titleBarMenuButtonPosition().x(), m_skin->titleBarMenuButtonPosition().y());
m_quitButton->move(width() - m_skin->titleBarQuitButtonPosition().x(), m_skin->titleBarQuitButtonPosition().y());
moveButtons();
repaint();
updateMask();
}
void TitleBar::moveButtons()
{
if (m_skin->titleBarFocusButtonAnchor() == Qt::AnchorLeft)
m_focusButton->move(m_skin->titleBarFocusButtonPosition().x(), m_skin->titleBarFocusButtonPosition().y());
else if (m_skin->titleBarFocusButtonAnchor() == Qt::AnchorRight)
m_focusButton->move(width() - m_skin->titleBarFocusButtonPosition().x(), m_skin->titleBarFocusButtonPosition().y());
if (m_skin->titleBarMenuButtonAnchor() == Qt::AnchorLeft)
m_menuButton->move(m_skin->titleBarMenuButtonPosition().x(), m_skin->titleBarMenuButtonPosition().y());
else if (m_skin->titleBarMenuButtonAnchor() == Qt::AnchorRight)
m_menuButton->move(width() - m_skin->titleBarMenuButtonPosition().x(), m_skin->titleBarMenuButtonPosition().y());
if (m_skin->titleBarQuitButtonAnchor() == Qt::AnchorLeft)
m_quitButton->move(m_skin->titleBarQuitButtonPosition().x(), m_skin->titleBarQuitButtonPosition().y());
else if (m_skin->titleBarQuitButtonAnchor() == Qt::AnchorRight)
m_quitButton->move(width() - m_skin->titleBarQuitButtonPosition().x(), m_skin->titleBarQuitButtonPosition().y());
}
void TitleBar::resizeEvent(QResizeEvent* event)
{
m_focusButton->move(width() - m_skin->titleBarFocusButtonPosition().x(), m_skin->titleBarFocusButtonPosition().y());
m_menuButton->move(width() - m_skin->titleBarMenuButtonPosition().x(), m_skin->titleBarMenuButtonPosition().y());
m_quitButton->move(width() - m_skin->titleBarQuitButtonPosition().x(), m_skin->titleBarQuitButtonPosition().y());
moveButtons();
updateMask();
......@@ -116,7 +129,11 @@ void TitleBar::paintEvent(QPaintEvent*)
font.setBold(m_skin->titleBarTextBold());
painter.setFont(font);
painter.drawText(m_skin->titleBarTextPosition(), title());
const QString title = this->title();
if (m_skin->titleBarTextCentered() && width() > m_skin->titleBarTextPosition().x() + painter.fontMetrics().width(title) + m_focusButton->width() + m_quitButton->width() + m_menuButton->width())
painter.drawText(0, 0, width(), height(), Qt::AlignCenter, title);
else
painter.drawText(m_skin->titleBarTextPosition(), title);
painter.end();
}
......
......@@ -58,6 +58,8 @@ class TitleBar : public QWidget
private:
void moveButtons();
MainWindow* m_mainWindow;
Skin* m_skin;
......
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