2018-01-10 10:22:05 +01:00
|
|
|
/* This file is part of Clementine.
|
|
|
|
Copyright 2018, Vikram Ambrose <ambroseworks@gmail.com>
|
|
|
|
|
|
|
|
Clementine is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Clementine is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2010-10-01 21:27:01 +02:00
|
|
|
|
|
|
|
#include "fancytabwidget.h"
|
|
|
|
#include "stylehelper.h"
|
2011-04-22 18:50:29 +02:00
|
|
|
#include "core/logging.h"
|
2010-10-01 21:27:01 +02:00
|
|
|
|
|
|
|
#include <QDebug>
|
|
|
|
|
2010-10-09 20:18:06 +02:00
|
|
|
#include <QMenu>
|
|
|
|
#include <QMouseEvent>
|
|
|
|
#include <QPainter>
|
|
|
|
#include <QSignalMapper>
|
2018-01-10 10:22:05 +01:00
|
|
|
#include <QTabBar>
|
|
|
|
#include <QStylePainter>
|
|
|
|
#include <QTimer>
|
2010-10-09 20:18:06 +02:00
|
|
|
#include <QVBoxLayout>
|
2018-01-10 10:22:05 +01:00
|
|
|
#include <QSettings>
|
2016-01-14 05:05:31 +01:00
|
|
|
|
2018-01-10 10:22:05 +01:00
|
|
|
const QSize FancyTabWidget::IconSize_LargeSidebar = QSize(24,24);
|
|
|
|
const QSize FancyTabWidget::IconSize_SmallSidebar = QSize(22,22);
|
2010-10-10 15:03:47 +02:00
|
|
|
|
2018-01-10 10:22:05 +01:00
|
|
|
const QSize FancyTabWidget::TabSize_LargeSidebar = QSize(70,47);
|
2010-10-10 15:03:47 +02:00
|
|
|
|
2018-01-10 10:22:05 +01:00
|
|
|
class FancyTabBar: public QTabBar {
|
2010-10-10 15:03:47 +02:00
|
|
|
|
2018-01-10 10:22:05 +01:00
|
|
|
private:
|
|
|
|
int mouseHoverTabIndex = -1;
|
|
|
|
QMap<QWidget*,QString> labelCache;
|
2010-10-10 15:03:47 +02:00
|
|
|
|
2018-01-10 10:22:05 +01:00
|
|
|
public:
|
|
|
|
explicit FancyTabBar(QWidget* parent=0) : QTabBar(parent) {
|
|
|
|
setMouseTracking(true);
|
|
|
|
}
|
2010-10-10 15:03:47 +02:00
|
|
|
|
2018-01-10 10:22:05 +01:00
|
|
|
QSize sizeHint() const {
|
|
|
|
QSize size(QTabBar::sizeHint());
|
2010-10-10 15:03:47 +02:00
|
|
|
|
2018-01-10 10:22:05 +01:00
|
|
|
FancyTabWidget *tabWidget = (FancyTabWidget*) parentWidget();
|
2018-02-01 09:50:42 +01:00
|
|
|
if(tabWidget->mode() == FancyTabWidget::Mode_Tabs ||
|
2018-01-10 10:22:05 +01:00
|
|
|
tabWidget->mode() == FancyTabWidget::Mode_IconOnlyTabs)
|
|
|
|
return size;
|
2010-10-10 15:03:47 +02:00
|
|
|
|
2018-01-10 10:22:05 +01:00
|
|
|
QSize tabSize(tabSizeHint(0));
|
|
|
|
size.setWidth(tabSize.width());
|
|
|
|
int guessHeight = tabSize.height()*count();
|
|
|
|
if(guessHeight > size.height())
|
|
|
|
size.setHeight(guessHeight);
|
|
|
|
return size;
|
2010-10-10 15:03:47 +02:00
|
|
|
}
|
|
|
|
|
2018-01-10 10:22:05 +01:00
|
|
|
int width() {
|
|
|
|
return tabSizeHint(0).width();
|
2010-10-10 15:03:47 +02:00
|
|
|
}
|
|
|
|
|
2018-01-10 10:22:05 +01:00
|
|
|
protected:
|
|
|
|
QSize tabSizeHint(int index) const {
|
|
|
|
FancyTabWidget *tabWidget = (FancyTabWidget*) parentWidget();
|
|
|
|
QSize size = FancyTabWidget::TabSize_LargeSidebar;
|
2010-10-10 15:03:47 +02:00
|
|
|
|
2018-01-10 10:22:05 +01:00
|
|
|
if(tabWidget->mode() != FancyTabWidget::Mode_LargeSidebar) {
|
|
|
|
size = QTabBar::tabSizeHint(index);
|
|
|
|
}
|
2010-10-10 15:03:47 +02:00
|
|
|
|
2018-01-10 10:22:05 +01:00
|
|
|
return size;
|
|
|
|
}
|
2010-10-10 15:03:47 +02:00
|
|
|
|
2018-01-10 10:22:05 +01:00
|
|
|
void leaveEvent(QEvent * event) {
|
|
|
|
mouseHoverTabIndex = -1;
|
|
|
|
update();
|
|
|
|
}
|
2010-10-10 15:03:47 +02:00
|
|
|
|
2018-01-10 10:22:05 +01:00
|
|
|
void mouseMoveEvent(QMouseEvent * event) {
|
|
|
|
QPoint pos = event->pos();
|
2010-10-10 15:03:47 +02:00
|
|
|
|
2018-01-10 10:22:05 +01:00
|
|
|
mouseHoverTabIndex = tabAt(pos);
|
|
|
|
if(mouseHoverTabIndex > -1)
|
|
|
|
update();
|
|
|
|
QTabBar::mouseMoveEvent(event);
|
|
|
|
}
|
2010-10-10 15:03:47 +02:00
|
|
|
|
2018-01-10 10:22:05 +01:00
|
|
|
void paintEvent(QPaintEvent *pe) {
|
|
|
|
FancyTabWidget *tabWidget = (FancyTabWidget*) parentWidget();
|
|
|
|
|
|
|
|
bool verticalTextTabs = false;
|
|
|
|
|
|
|
|
if(tabWidget->mode() == FancyTabWidget::Mode_SmallSidebar)
|
|
|
|
verticalTextTabs = true;
|
|
|
|
|
|
|
|
// Restore any label text that was hidden/cached for the IconOnlyTabs mode
|
|
|
|
if(labelCache.count() > 0 && tabWidget->mode() != FancyTabWidget::Mode_IconOnlyTabs) {
|
|
|
|
for(int i =0; i < count(); i++) {
|
|
|
|
setTabText(i,labelCache[tabWidget->widget(i)]);
|
|
|
|
}
|
|
|
|
labelCache.clear();
|
|
|
|
}
|
|
|
|
if(tabWidget->mode() != FancyTabWidget::Mode_LargeSidebar &&
|
|
|
|
tabWidget->mode() != FancyTabWidget::Mode_SmallSidebar) {
|
|
|
|
// Cache and hide label text for IconOnlyTabs mode
|
|
|
|
if(tabWidget->mode() == FancyTabWidget::Mode_IconOnlyTabs && labelCache.count() == 0) {
|
|
|
|
for(int i =0; i < count(); i++) {
|
|
|
|
labelCache[tabWidget->widget(i)] = tabText(i);
|
|
|
|
setTabText(i,"");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
QTabBar::paintEvent(pe);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QStylePainter p(this);
|
|
|
|
|
2018-02-01 09:50:42 +01:00
|
|
|
|
2018-01-10 10:22:05 +01:00
|
|
|
for (int index = 0; index < count(); index++) {
|
|
|
|
const bool selected = tabWidget->currentIndex() == index;;
|
|
|
|
|
|
|
|
QRect tabrect = tabRect(index);
|
|
|
|
|
|
|
|
QRect selectionRect = tabrect;
|
|
|
|
|
|
|
|
if(selected) {
|
|
|
|
// Selection highlight
|
|
|
|
p.save();
|
|
|
|
QLinearGradient grad(selectionRect.topLeft(), selectionRect.topRight());
|
|
|
|
grad.setColorAt(0, QColor(255, 255, 255, 140));
|
|
|
|
grad.setColorAt(1, QColor(255, 255, 255, 210));
|
|
|
|
p.fillRect(selectionRect.adjusted(0,0,0,-1), grad);
|
|
|
|
p.restore();
|
|
|
|
|
|
|
|
// shadow lines
|
|
|
|
p.setPen(QColor(0, 0, 0, 110));
|
|
|
|
p.drawLine(selectionRect.topLeft() + QPoint(1, -1), selectionRect.topRight() - QPoint(0, 1));
|
|
|
|
p.drawLine(selectionRect.bottomLeft(), selectionRect.bottomRight());
|
|
|
|
p.setPen(QColor(0, 0, 0, 40));
|
|
|
|
p.drawLine(selectionRect.topLeft(), selectionRect.bottomLeft());
|
|
|
|
|
|
|
|
// highlights
|
|
|
|
p.setPen(QColor(255, 255, 255, 50));
|
|
|
|
p.drawLine(selectionRect.topLeft() + QPoint(0, -2), selectionRect.topRight() - QPoint(0, 2));
|
|
|
|
p.drawLine(selectionRect.bottomLeft() + QPoint(0, 1), selectionRect.bottomRight() + QPoint(0, 1));
|
|
|
|
p.setPen(QColor(255, 255, 255, 40));
|
|
|
|
p.drawLine(selectionRect.topLeft() + QPoint(0, 0), selectionRect.topRight());
|
|
|
|
p.drawLine(selectionRect.topRight() + QPoint(0, 1), selectionRect.bottomRight() - QPoint(0, 1));
|
|
|
|
p.drawLine(selectionRect.bottomLeft() + QPoint(0, -1), selectionRect.bottomRight() - QPoint(0, 1));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Mouse hover effect
|
|
|
|
if(!selected && index == mouseHoverTabIndex && isTabEnabled(index))
|
|
|
|
{
|
|
|
|
p.save();
|
|
|
|
QLinearGradient grad(selectionRect.topLeft(), selectionRect.topRight());
|
|
|
|
grad.setColorAt(0, Qt::transparent);
|
|
|
|
grad.setColorAt(0.5, QColor(255, 255, 255, 40));
|
|
|
|
grad.setColorAt(1, Qt::transparent);
|
|
|
|
p.fillRect(selectionRect, grad);
|
|
|
|
p.setPen(QPen(grad, 1.0));
|
|
|
|
p.drawLine(selectionRect.topLeft(), selectionRect.topRight());
|
|
|
|
p.drawLine(selectionRect.bottomRight(), selectionRect.bottomLeft());
|
|
|
|
p.restore();
|
|
|
|
}
|
|
|
|
|
2018-02-01 09:50:42 +01:00
|
|
|
// Label (Icon and Text)
|
2018-01-10 10:22:05 +01:00
|
|
|
{
|
|
|
|
p.save();
|
|
|
|
QTransform m;
|
|
|
|
int textFlags;
|
|
|
|
Qt::Alignment iconFlags;
|
|
|
|
|
|
|
|
QRect tabrectText;
|
|
|
|
QRect tabrectLabel;
|
|
|
|
|
|
|
|
if (verticalTextTabs) {
|
|
|
|
m = QTransform::fromTranslate(tabrect.left(), tabrect.bottom());
|
|
|
|
m.rotate(-90);
|
|
|
|
textFlags = Qt::AlignLeft | Qt::AlignVCenter ;
|
|
|
|
iconFlags = Qt::AlignLeft | Qt::AlignVCenter;
|
|
|
|
|
|
|
|
tabrectLabel = QRect(QPoint(0, 0), m.mapRect(tabrect).size());
|
|
|
|
|
|
|
|
tabrectText = tabrectLabel;
|
|
|
|
tabrectText.translate(30,0);
|
|
|
|
} else {
|
|
|
|
m = QTransform::fromTranslate(tabrect.left(), tabrect.top());
|
|
|
|
textFlags = Qt::AlignHCenter | Qt::AlignBottom ;
|
|
|
|
iconFlags = Qt::AlignHCenter | Qt::AlignTop;
|
|
|
|
|
|
|
|
tabrectLabel = QRect(QPoint(0, 0), m.mapRect(tabrect).size());
|
|
|
|
|
|
|
|
tabrectText = tabrectLabel;
|
|
|
|
tabrectText.translate(0,-5);
|
|
|
|
}
|
|
|
|
|
|
|
|
p.setTransform(m);
|
|
|
|
|
|
|
|
QFont boldFont(p.font());
|
|
|
|
boldFont.setPointSizeF(Utils::StyleHelper::sidebarFontSize());
|
|
|
|
boldFont.setBold(true);
|
|
|
|
p.setFont(boldFont);
|
|
|
|
|
2018-02-01 09:50:42 +01:00
|
|
|
// Text drop shadow color
|
2018-01-10 10:22:05 +01:00
|
|
|
p.setPen(selected ? QColor(255,255,255,160) : QColor(0,0,0,110) );
|
|
|
|
p.translate(0, 3);
|
|
|
|
p.drawText(tabrectText, textFlags, tabText(index));
|
|
|
|
|
2018-02-01 09:50:42 +01:00
|
|
|
// Text foreground color
|
2018-01-10 10:22:05 +01:00
|
|
|
p.translate(0, -1);
|
|
|
|
p.setPen(selected ? QColor(60, 60, 60) : Utils::StyleHelper::panelTextColor());
|
|
|
|
p.drawText(tabrectText, textFlags, tabText(index));
|
|
|
|
|
|
|
|
|
|
|
|
// Draw the icon
|
|
|
|
QRect tabrectIcon;
|
|
|
|
const int PADDING = 5;
|
|
|
|
if(verticalTextTabs) {
|
|
|
|
tabrectIcon = tabrectLabel;
|
2018-02-01 09:50:42 +01:00
|
|
|
tabrectIcon.setSize(FancyTabWidget::IconSize_SmallSidebar);
|
2018-01-10 10:22:05 +01:00
|
|
|
tabrectIcon.translate(PADDING,PADDING);
|
|
|
|
} else {
|
|
|
|
tabrectIcon = tabrectLabel;
|
2018-02-01 09:50:42 +01:00
|
|
|
tabrectIcon.setSize(FancyTabWidget::IconSize_LargeSidebar);
|
2018-01-10 10:22:05 +01:00
|
|
|
// Center the icon
|
2018-02-01 09:50:42 +01:00
|
|
|
const int moveRight = (FancyTabWidget::TabSize_LargeSidebar.width() -
|
2018-01-10 10:22:05 +01:00
|
|
|
FancyTabWidget::IconSize_LargeSidebar.width() -1)/2;
|
|
|
|
tabrectIcon.translate(moveRight,PADDING);
|
|
|
|
}
|
|
|
|
tabIcon(index).paint(&p, tabrectIcon, iconFlags);
|
|
|
|
p.restore();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2010-10-10 15:03:47 +02:00
|
|
|
|
2018-01-10 10:22:05 +01:00
|
|
|
// Spacers are just disabled pages
|
|
|
|
void FancyTabWidget::addSpacer() {
|
|
|
|
QWidget *spacer = new QWidget();
|
|
|
|
const int index = addTab(spacer,QIcon(),QString());
|
|
|
|
setTabEnabled(index,false);
|
2010-10-02 12:49:48 +02:00
|
|
|
}
|
|
|
|
|
2018-01-10 10:22:05 +01:00
|
|
|
void FancyTabWidget::setBackgroundPixmap(const QPixmap& pixmap) {
|
|
|
|
background_pixmap_ = pixmap;
|
|
|
|
update();
|
2010-10-01 21:27:01 +02:00
|
|
|
}
|
|
|
|
|
2018-01-10 10:22:05 +01:00
|
|
|
void FancyTabWidget::setCurrentIndex(int index) {
|
|
|
|
QWidget* currentPage = widget(index);
|
2010-10-01 21:27:01 +02:00
|
|
|
|
2018-01-10 10:22:05 +01:00
|
|
|
QLayout *layout = currentPage->layout();
|
|
|
|
if(bottom_widget_ != nullptr)
|
|
|
|
layout->addWidget(bottom_widget_);
|
2010-10-01 21:27:01 +02:00
|
|
|
|
2018-01-10 10:22:05 +01:00
|
|
|
QTabWidget::setCurrentIndex(index);
|
2010-10-01 21:27:01 +02:00
|
|
|
}
|
|
|
|
|
2018-01-10 10:22:05 +01:00
|
|
|
// Slot
|
|
|
|
void FancyTabWidget::currentTabChanged(int index) {
|
|
|
|
QWidget* currentPage = currentWidget();
|
2010-10-02 12:49:48 +02:00
|
|
|
|
2018-01-10 10:22:05 +01:00
|
|
|
QLayout *layout = currentPage->layout();
|
|
|
|
if(bottom_widget_ != nullptr)
|
|
|
|
layout->addWidget(bottom_widget_);
|
2018-11-11 17:48:09 +01:00
|
|
|
emit CurrentChanged(index);
|
2010-10-01 21:27:01 +02:00
|
|
|
}
|
|
|
|
|
2018-02-01 09:50:42 +01:00
|
|
|
FancyTabWidget::FancyTabWidget(QWidget* parent) : QTabWidget(parent),
|
2018-01-10 10:22:05 +01:00
|
|
|
menu_(nullptr),
|
|
|
|
mode_(Mode_None),
|
|
|
|
bottom_widget_(nullptr) {
|
|
|
|
FancyTabBar *tabBar = new FancyTabBar(this);
|
2010-10-01 21:27:01 +02:00
|
|
|
|
2018-01-10 10:22:05 +01:00
|
|
|
setTabBar(tabBar);
|
|
|
|
setTabPosition(QTabWidget::West);
|
|
|
|
setMovable(true);
|
2013-04-01 17:54:33 +02:00
|
|
|
|
2018-01-10 10:22:05 +01:00
|
|
|
connect(tabBar, SIGNAL(currentChanged(int)), this, SLOT(currentTabChanged(int)));
|
2013-04-01 17:54:33 +02:00
|
|
|
}
|
|
|
|
|
2019-09-11 01:29:48 +02:00
|
|
|
void FancyTabWidget::loadSettings(const QSettings& settings) {
|
2019-09-11 01:27:08 +02:00
|
|
|
for (int i = 0; i < count(); i++) {
|
|
|
|
int originalIndex = tabBar()->tabData(i).toInt();
|
|
|
|
QString k = "tab_index_" + QString::number(originalIndex);
|
2010-10-01 21:27:01 +02:00
|
|
|
|
2019-09-11 01:27:08 +02:00
|
|
|
int newIndex = settings.value(k, i).toInt();
|
2010-10-01 21:27:01 +02:00
|
|
|
|
2019-09-11 01:27:08 +02:00
|
|
|
if (newIndex >= 0)
|
|
|
|
tabBar()->moveTab(i, newIndex);
|
|
|
|
else
|
|
|
|
removeTab(i); // Does not delete page
|
|
|
|
}
|
2010-10-02 14:31:11 +02:00
|
|
|
}
|
|
|
|
|
2019-09-07 06:02:48 +02:00
|
|
|
void FancyTabWidget::saveSettings(QSettings* settings) {
|
|
|
|
for (int i = 0; i < count(); i++) {
|
|
|
|
int originalIndex = tabBar()->tabData(i).toInt();
|
2019-09-11 01:27:08 +02:00
|
|
|
QString k = "tab_index_" + QString::number(originalIndex);
|
2010-10-01 21:27:01 +02:00
|
|
|
|
2019-09-11 01:27:08 +02:00
|
|
|
settings->setValue(k, i);
|
2019-09-07 06:02:48 +02:00
|
|
|
}
|
2010-10-01 21:27:01 +02:00
|
|
|
}
|
|
|
|
|
2010-10-02 12:49:48 +02:00
|
|
|
|
2018-01-10 10:22:05 +01:00
|
|
|
void FancyTabWidget::addBottomWidget(QWidget* widget) {
|
|
|
|
bottom_widget_ = widget;
|
2010-10-02 12:49:48 +02:00
|
|
|
}
|
|
|
|
|
2018-01-10 10:22:05 +01:00
|
|
|
int FancyTabWidget::addTab(QWidget * page, const QIcon & icon, const QString & label) {
|
|
|
|
return insertTab(count(),page,icon,label);
|
2010-10-01 21:27:01 +02:00
|
|
|
}
|
|
|
|
|
2018-01-10 10:22:05 +01:00
|
|
|
int FancyTabWidget::insertTab(int index, QWidget * page, const QIcon & icon, const QString & label) {
|
2018-02-01 09:50:42 +01:00
|
|
|
// In order to achieve the same effect as the "Bottom Widget" of the
|
2018-01-10 10:22:05 +01:00
|
|
|
// old Nokia based FancyTabWidget a VBoxLayout is used on each page
|
|
|
|
QVBoxLayout *layout = new QVBoxLayout();
|
|
|
|
layout->setSpacing(0);
|
|
|
|
layout->setContentsMargins(0,0,0,0);
|
|
|
|
layout->addWidget(page);
|
2010-10-01 21:27:01 +02:00
|
|
|
|
2018-01-10 10:22:05 +01:00
|
|
|
QWidget *newPage = new QWidget();
|
|
|
|
newPage->setLayout(layout);
|
2010-10-01 21:27:01 +02:00
|
|
|
|
2018-01-10 10:22:05 +01:00
|
|
|
const int actualIndex = QTabWidget::insertTab(index,newPage,icon,label);
|
2010-10-01 21:27:01 +02:00
|
|
|
|
2018-01-10 10:22:05 +01:00
|
|
|
// Remember the original index. Needed to save order of tabs
|
|
|
|
tabBar()->setTabData(actualIndex,QVariant(actualIndex));
|
|
|
|
return actualIndex;
|
2010-10-09 20:18:06 +02:00
|
|
|
}
|
|
|
|
|
2018-01-10 10:22:05 +01:00
|
|
|
void FancyTabWidget::paintEvent(QPaintEvent *pe) {
|
|
|
|
if(mode() != FancyTabWidget::Mode_LargeSidebar &&
|
|
|
|
mode() != FancyTabWidget::Mode_SmallSidebar) {
|
|
|
|
QTabWidget::paintEvent(pe);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
QStylePainter p(this);
|
|
|
|
|
2018-02-01 09:50:42 +01:00
|
|
|
// The brown color (Ubuntu) you see on the background gradient
|
2018-01-10 10:22:05 +01:00
|
|
|
QColor baseColor = StyleHelper::baseColor();
|
|
|
|
|
|
|
|
QRect backgroundRect = rect();
|
|
|
|
backgroundRect.setWidth(((FancyTabBar*)tabBar())->width());
|
|
|
|
p.fillRect(backgroundRect,baseColor);
|
|
|
|
|
2018-02-01 09:50:42 +01:00
|
|
|
// Horizontal gradient over the sidebar from transparent to dark
|
2018-01-10 10:22:05 +01:00
|
|
|
Utils::StyleHelper::verticalGradient(&p,backgroundRect,backgroundRect,false);
|
|
|
|
|
|
|
|
// Draw the translucent png graphics over the gradient fill
|
|
|
|
{
|
|
|
|
if (!background_pixmap_.isNull()) {
|
|
|
|
QRect pixmap_rect(background_pixmap_.rect());
|
|
|
|
pixmap_rect.moveTo(backgroundRect.topLeft());
|
|
|
|
|
|
|
|
while (pixmap_rect.top() < backgroundRect.bottom()) {
|
|
|
|
QRect source_rect(pixmap_rect.intersected(backgroundRect));
|
|
|
|
source_rect.moveTo(0, 0);
|
|
|
|
p.drawPixmap(pixmap_rect.topLeft(), background_pixmap_,source_rect);
|
|
|
|
pixmap_rect.moveTop(pixmap_rect.bottom() - 10);
|
|
|
|
}
|
|
|
|
}
|
2010-10-09 20:18:06 +02:00
|
|
|
}
|
2010-10-01 21:27:01 +02:00
|
|
|
|
2018-01-10 10:22:05 +01:00
|
|
|
// Shadow effect of the background
|
|
|
|
{
|
|
|
|
QColor light(255, 255, 255, 80);
|
|
|
|
p.setPen(light);
|
|
|
|
p.drawLine(backgroundRect.topRight() - QPoint(1, 0), backgroundRect.bottomRight() - QPoint(1, 0));
|
|
|
|
QColor dark(0, 0, 0, 90);
|
|
|
|
p.setPen(dark);
|
|
|
|
p.drawLine(backgroundRect.topLeft(), backgroundRect.bottomLeft());
|
|
|
|
|
|
|
|
p.setPen(Utils::StyleHelper::borderColor());
|
|
|
|
p.drawLine(backgroundRect.topRight(), backgroundRect.bottomRight());
|
|
|
|
}
|
2012-03-11 18:57:15 +01:00
|
|
|
|
2010-10-01 21:27:01 +02:00
|
|
|
}
|
|
|
|
|
2018-01-10 10:22:05 +01:00
|
|
|
void FancyTabWidget::tabBarUpdateGeometry() {
|
|
|
|
tabBar()->updateGeometry();
|
2010-10-01 21:27:01 +02:00
|
|
|
}
|
|
|
|
|
2018-01-10 10:22:05 +01:00
|
|
|
void FancyTabWidget::SetMode(FancyTabWidget::Mode mode) {
|
|
|
|
mode_ = mode;
|
2010-10-01 21:27:01 +02:00
|
|
|
|
2018-02-01 09:50:42 +01:00
|
|
|
if(mode == FancyTabWidget::Mode_Tabs ||
|
2018-01-10 10:22:05 +01:00
|
|
|
mode == FancyTabWidget::Mode_IconOnlyTabs) {
|
|
|
|
setTabPosition(QTabWidget::North);
|
|
|
|
} else {
|
|
|
|
setTabPosition(QTabWidget::West);
|
2010-10-02 14:09:06 +02:00
|
|
|
}
|
|
|
|
|
2018-01-10 10:22:05 +01:00
|
|
|
tabBar()->updateGeometry();
|
|
|
|
updateGeometry();
|
2010-10-01 21:27:01 +02:00
|
|
|
|
2018-02-01 09:50:42 +01:00
|
|
|
// There appears to be a bug in QTabBar which causes tabSizeHint
|
2018-01-10 10:22:05 +01:00
|
|
|
// to be ignored thus the need for this second shot repaint
|
|
|
|
QTimer::singleShot(1,this,SLOT(tabBarUpdateGeometry()));
|
2010-10-01 21:27:01 +02:00
|
|
|
|
2018-01-10 10:22:05 +01:00
|
|
|
emit ModeChanged(mode);
|
2010-10-01 21:27:01 +02:00
|
|
|
}
|
|
|
|
|
2018-01-10 10:22:05 +01:00
|
|
|
void FancyTabWidget::addMenuItem(QSignalMapper* mapper, QActionGroup* group,
|
2010-10-09 20:18:06 +02:00
|
|
|
const QString& text, Mode mode) {
|
|
|
|
QAction* action = group->addAction(text);
|
|
|
|
action->setCheckable(true);
|
|
|
|
mapper->setMapping(action, mode);
|
|
|
|
connect(action, SIGNAL(triggered()), mapper, SLOT(map()));
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
if (mode == mode_) action->setChecked(true);
|
2010-10-01 21:27:01 +02:00
|
|
|
}
|
2010-10-06 20:16:49 +02:00
|
|
|
|
2010-10-10 15:12:42 +02:00
|
|
|
|
2018-01-10 10:22:05 +01:00
|
|
|
void FancyTabWidget::contextMenuEvent(QContextMenuEvent* e) {
|
|
|
|
if (!menu_) {
|
|
|
|
menu_ = new QMenu(this);
|
2010-12-04 19:03:53 +01:00
|
|
|
|
2018-01-10 10:22:05 +01:00
|
|
|
QSignalMapper* mapper = new QSignalMapper(this);
|
|
|
|
QActionGroup* group = new QActionGroup(this);
|
|
|
|
addMenuItem(mapper, group, tr("Large sidebar"), Mode_LargeSidebar);
|
|
|
|
addMenuItem(mapper, group, tr("Small sidebar"), Mode_SmallSidebar);
|
|
|
|
addMenuItem(mapper, group, tr("Plain sidebar"), Mode_PlainSidebar);
|
|
|
|
addMenuItem(mapper, group, tr("Tabs on top"), Mode_Tabs);
|
|
|
|
addMenuItem(mapper, group, tr("Icons on top"), Mode_IconOnlyTabs);
|
|
|
|
menu_->addActions(group->actions());
|
2010-12-04 19:03:53 +01:00
|
|
|
|
2018-01-10 10:22:05 +01:00
|
|
|
connect(mapper, SIGNAL(mapped(int)), SLOT(SetMode(int)));
|
2010-10-09 20:18:06 +02:00
|
|
|
}
|
|
|
|
|
2018-01-10 10:22:05 +01:00
|
|
|
menu_->popup(e->globalPos());
|
2010-10-06 20:16:49 +02:00
|
|
|
}
|