Falkon Develop
Cross-platform Qt-based web browser
fancytabwidget.cpp
Go to the documentation of this file.
1/**************************************************************************
2**
3** This file is part of Qt Creator
4**
5** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
6**
7** Contact: Nokia Corporation (qt-info@nokia.com)
8**
9** Commercial Usage
10**
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
15**
16** GNU Lesser General Public License Usage
17**
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 2.1 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 2.1 requirements
23** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24**
25** If you are unsure which license is appropriate for your use, please
26** contact the sales department at http://qt.nokia.com/contact.
27**
28**************************************************************************/
29
30#include "fancytabwidget.h"
31#include "stylehelper.h"
32
33#include <QAnimationGroup>
34#include <QColorDialog>
35#include <QHBoxLayout>
36#include <QMenu>
37#include <QMouseEvent>
38#include <QPainter>
39#include <QSignalMapper>
40#include <QSplitter>
41#include <QStackedLayout>
42#include <QStyleOptionTab>
43#include <QToolButton>
44#include <QToolTip>
45#include <QVBoxLayout>
46#include <QActionGroup>
47//#include <QWindowsStyle>
48
49using namespace Core;
50using namespace Internal;
51
52const int FancyTabBar::m_rounding = 22;
53const int FancyTabBar::m_textPadding = 4;
54
55void FancyTabProxyStyle::drawControl(
56 ControlElement element, const QStyleOption* option,
57 QPainter* p, const QWidget* widget) const
58{
59
60 const auto* v_opt = qstyleoption_cast<const QStyleOptionTab*>(option);
61
62 if (element != CE_TabBarTab || !v_opt) {
63 QProxyStyle::drawControl(element, option, p, widget);
64 return;
65 }
66
67 const QRect rect = v_opt->rect;
68 const bool selected = v_opt->state & State_Selected;
69 const bool vertical_tabs = v_opt->shape == QTabBar::RoundedWest;
70 const QString text = v_opt->text;
71
72 if (selected) {
73 //background
74 p->save();
75 QLinearGradient grad(rect.topLeft(), rect.topRight());
76 grad.setColorAt(0, QColor(255, 255, 255, 140));
77 grad.setColorAt(1, QColor(255, 255, 255, 210));
78 p->fillRect(rect.adjusted(0, 0, 0, -1), grad);
79 p->restore();
80
81 //shadows
82 p->setPen(QColor(0, 0, 0, 110));
83 p->drawLine(rect.topLeft() + QPoint(1, -1), rect.topRight() - QPoint(0, 1));
84 p->drawLine(rect.bottomLeft(), rect.bottomRight());
85 p->setPen(QColor(0, 0, 0, 40));
86 p->drawLine(rect.topLeft(), rect.bottomLeft());
87
88 //highlights
89 p->setPen(QColor(255, 255, 255, 50));
90 p->drawLine(rect.topLeft() + QPoint(0, -2), rect.topRight() - QPoint(0, 2));
91 p->drawLine(rect.bottomLeft() + QPoint(0, 1), rect.bottomRight() + QPoint(0, 1));
92 p->setPen(QColor(255, 255, 255, 40));
93 p->drawLine(rect.topLeft() + QPoint(0, 0), rect.topRight());
94 p->drawLine(rect.topRight() + QPoint(0, 1), rect.bottomRight() - QPoint(0, 1));
95 p->drawLine(rect.bottomLeft() + QPoint(0, -1), rect.bottomRight() - QPoint(0, 1));
96 }
97
98 QTransform m;
99 if (vertical_tabs) {
100 m = QTransform::fromTranslate(rect.left(), rect.bottom());
101 m.rotate(-90);
102 }
103 else {
104 m = QTransform::fromTranslate(rect.left(), rect.top());
105 }
106
107 const QRect draw_rect(QPoint(0, 0), m.mapRect(rect).size());
108
109 p->save();
110 p->setTransform(m);
111
112 QRect icon_rect(QPoint(8, 0), v_opt->iconSize);
113 QRect text_rect(icon_rect.topRight() + QPoint(4, 0), draw_rect.size());
114 text_rect.setRight(draw_rect.width());
115 icon_rect.translate(0, (draw_rect.height() - icon_rect.height()) / 2);
116
117 QFont boldFont(p->font());
118 boldFont.setPointSizeF(Utils::StyleHelper::sidebarFontSize());
119 boldFont.setBold(true);
120 p->setFont(boldFont);
121 p->setPen(selected ? QColor(255, 255, 255, 160) : QColor(0, 0, 0, 110));
122 int textFlags = Qt::AlignHCenter | Qt::AlignVCenter;
123 p->drawText(text_rect, textFlags, text);
124 p->setPen(selected ? QColor(60, 60, 60) : Utils::StyleHelper::panelTextColor());
125 if (widget) {
126 const QString fader_key = QSL("tab_") + text + QSL("_fader");
127 const QString animation_key = QSL("tab_") + text + QSL("_animation");
128
129 const QString tab_hover = widget->property("tab_hover").toString();
130 int fader = widget->property(fader_key.toUtf8().constData()).toInt();
131 auto* animation = widget->property(animation_key.toUtf8().constData()).value<QPropertyAnimation*>();
132
133 if (!animation) {
134 auto* mut_widget = const_cast<QWidget*>(widget);
135 fader = 0;
136 mut_widget->setProperty(fader_key.toUtf8().constData(), fader);
137 animation = new QPropertyAnimation(mut_widget, fader_key.toUtf8(), mut_widget);
138 connect(animation, SIGNAL(valueChanged(QVariant)), mut_widget, SLOT(update()));
139 mut_widget->setProperty(animation_key.toUtf8().constData(), QVariant::fromValue(animation));
140 }
141
142 if (text == tab_hover) {
143 if (animation->state() != QAbstractAnimation::Running && fader != 40) {
144 animation->stop();
145 animation->setDuration(80);
146 animation->setEndValue(40);
147 animation->start();
148 }
149 }
150 else {
151 if (animation->state() != QAbstractAnimation::Running && fader != 0) {
152 animation->stop();
153 animation->setDuration(160);
154 animation->setEndValue(0);
155 animation->start();
156 }
157 }
158
159 if (!selected) {
160 p->save();
161 p->fillRect(draw_rect, QColor(255, 255, 255, fader));
162 p->setPen(QPen(QColor(255, 255, 255, fader), 1.0));
163 p->drawLine(draw_rect.topLeft(), vertical_tabs ? draw_rect.bottomLeft() : draw_rect.topRight());
164 p->drawLine(draw_rect.bottomRight(), vertical_tabs ? draw_rect.topRight() : draw_rect.bottomLeft());
165 p->restore();
166 }
167 }
168
169 Utils::StyleHelper::drawIconWithShadow(v_opt->icon, icon_rect, p, selected ? QIcon::Selected : QIcon::Normal);
170
171 p->drawText(text_rect.translated(0, -1), textFlags, text);
172
173 p->restore();
174}
175
176void FancyTabProxyStyle::polish(QWidget* widget)
177{
178 if (QString::fromLatin1(widget->metaObject()->className()) == QLatin1String("QTabBar")) {
179 widget->setMouseTracking(true);
180 widget->installEventFilter(this);
181 }
182 QProxyStyle::polish(widget);
183}
184
185void FancyTabProxyStyle::polish(QApplication* app)
186{
187 QProxyStyle::polish(app);
188}
189
190void FancyTabProxyStyle::polish(QPalette &palette)
191{
192 QProxyStyle::polish(palette);
193}
194
195bool FancyTabProxyStyle::eventFilter(QObject* o, QEvent* e)
196{
197 auto* bar = qobject_cast<QTabBar*>(o);
198 if (bar && (e->type() == QEvent::MouseMove || e->type() == QEvent::Leave)) {
199 auto* event = static_cast<QMouseEvent*>(e);
200 const QString old_hovered_tab = bar->property("tab_hover").toString();
201 const QString hovered_tab = e->type() == QEvent::Leave ? QString() : bar->tabText(bar->tabAt(event->pos()));
202 bar->setProperty("tab_hover", hovered_tab);
203
204 if (old_hovered_tab != hovered_tab) {
205 bar->update();
206 }
207 }
208
209 return false;
210}
211
212FancyTab::FancyTab(QWidget* tabbar)
213 : QWidget(tabbar), tabbar(tabbar), m_fader(0)
214{
215 animator.setPropertyName("fader");
216 animator.setTargetObject(this);
217 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
218}
219
221{
222 animator.stop();
223 animator.setDuration(80);
224 animator.setEndValue(40);
225 animator.start();
226}
227
229{
230 animator.stop();
231 animator.setDuration(160);
232 animator.setEndValue(0);
233 animator.start();
234}
235
237{
238 m_fader = value;
239 tabbar->update();
240}
241
243 : QWidget(parent)
244 , m_currentIndex(-1)
245{
246 setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
247 //setStyle(new QWindowsStyle);
248 setMinimumWidth(qMax(2 * m_rounding, 40));
249 setAttribute(Qt::WA_Hover, true);
250 setFocusPolicy(Qt::NoFocus);
251 setMouseTracking(true); // Needed for hover events
252 m_triggerTimer.setSingleShot(true);
253
254 auto* layout = new QVBoxLayout;
255 layout->addSpacerItem(new QSpacerItem(0, 0, QSizePolicy::Fixed, QSizePolicy::Expanding));
256 layout->setSpacing(0);
257 layout->setContentsMargins(0, 0, 0, 0);
258 setLayout(layout);
259
260 // We use a zerotimer to keep the sidebar responsive
261 connect(&m_triggerTimer, &QTimer::timeout, this, &FancyTabBar::emitCurrentIndex);
262}
263
265{
266 delete style();
267}
268
270{
271 QFont boldFont(font());
272 boldFont.setPointSizeF(Utils::StyleHelper::sidebarFontSize());
273 boldFont.setBold(true);
274 QFontMetrics fm(boldFont);
275 int spacing = 8;
276 int width = 60 + spacing + 2;
277 int iconHeight = 32;
278 QSize ret(width, iconHeight + spacing + fm.height());
279 return ret;
280}
281
282QSize FancyTabBar::tabSizeHint(bool minimum) const
283{
284 QFont boldFont(font());
285 boldFont.setPointSizeF(Utils::StyleHelper::sidebarFontSize());
286 boldFont.setBold(true);
287 QFontMetrics fm(boldFont);
288 int spacing = 8;
289 int width = 60 + spacing + 2;
290 int iconHeight = minimum ? 0 : 32;
291 return QSize(width, iconHeight + spacing + fm.height());
292}
293
294void FancyTabBar::paintEvent(QPaintEvent* event)
295{
296 Q_UNUSED(event)
297 QPainter p(this);
298
299 for (int i = 0; i < count(); ++i)
300 if (i != currentIndex()) {
301 paintTab(&p, i);
302 }
303
304 // paint active tab last, since it overlaps the neighbors
305 if (currentIndex() != -1) {
306 paintTab(&p, currentIndex());
307 }
308}
309
310void FancyTab::enterEvent(QEnterEvent*)
311{
312 fadeIn();
313}
314
316{
317 fadeOut();
318}
319
321{
322 QSize sh = tabSizeHint();
323 return QSize(sh.width(), sh.height() * m_tabs.count());
324}
325
327{
328 QSize sh = tabSizeHint(true);
329 return QSize(sh.width(), sh.height() * m_tabs.count());
330}
331
332QRect FancyTabBar::tabRect(int index) const
333{
334 return m_tabs[index]->geometry();
335}
336
337QString FancyTabBar::tabToolTip(int index) const
338{
339 return m_tabs[index]->toolTip();
340}
341
342void FancyTabBar::setTabToolTip(int index, const QString &toolTip)
343{
344 m_tabs[index]->setToolTip(toolTip);
345}
346
347// This keeps the sidebar responsive since
348// we get a repaint before loading the
349// mode itself
351{
352 Q_EMIT currentChanged(m_currentIndex);
353}
354
356{
357 e->accept();
358 for (int index = 0; index < m_tabs.count(); ++index) {
359 if (tabRect(index).contains(e->pos())) {
360 m_currentIndex = index;
361 update();
362 m_triggerTimer.start(0);
363 break;
364 }
365 }
366}
367
368void FancyTabBar::addTab(const QIcon &icon, const QString &label)
369{
370 auto* tab = new FancyTab(this);
371 tab->icon = icon;
372 tab->text = label;
373 m_tabs.append(tab);
374 qobject_cast<QVBoxLayout*>(layout())->insertWidget(layout()->count() - 1, tab);
375}
376
378{
379 qobject_cast<QVBoxLayout*>(layout())->insertSpacerItem(layout()->count() - 1,
380 new QSpacerItem(0, size, QSizePolicy::Fixed, QSizePolicy::Maximum));
381}
382
383void FancyTabBar::paintTab(QPainter* painter, int tabIndex) const
384{
385 if (!validIndex(tabIndex)) {
386 qWarning("invalid index");
387 return;
388 }
389 painter->save();
390
391 QRect rect = tabRect(tabIndex);
392 bool selected = (tabIndex == m_currentIndex);
393
394 if (selected) {
395 //background
396 painter->save();
397 QLinearGradient grad(rect.topLeft(), rect.topRight());
398 grad.setColorAt(0, QColor(255, 255, 255, 140));
399 grad.setColorAt(1, QColor(255, 255, 255, 210));
400 painter->fillRect(rect.adjusted(0, 0, 0, -1), grad);
401 painter->restore();
402
403 //shadows
404 painter->setPen(QColor(0, 0, 0, 110));
405 painter->drawLine(rect.topLeft() + QPoint(1, -1), rect.topRight() - QPoint(0, 1));
406 painter->drawLine(rect.bottomLeft(), rect.bottomRight());
407 painter->setPen(QColor(0, 0, 0, 40));
408 painter->drawLine(rect.topLeft(), rect.bottomLeft());
409
410 //highlights
411 painter->setPen(QColor(255, 255, 255, 50));
412 painter->drawLine(rect.topLeft() + QPoint(0, -2), rect.topRight() - QPoint(0, 2));
413 painter->drawLine(rect.bottomLeft() + QPoint(0, 1), rect.bottomRight() + QPoint(0, 1));
414 painter->setPen(QColor(255, 255, 255, 40));
415 painter->drawLine(rect.topLeft() + QPoint(0, 0), rect.topRight());
416 painter->drawLine(rect.topRight() + QPoint(0, 1), rect.bottomRight() - QPoint(0, 1));
417 painter->drawLine(rect.bottomLeft() + QPoint(0, -1), rect.bottomRight() - QPoint(0, 1));
418 }
419
420 // QString tabText(painter->fontMetrics().elidedText(this->tabText(tabIndex), Qt::ElideMiddle, width()));
421 QRect tabTextRect(tabRect(tabIndex));
422 QRect tabIconRect(tabTextRect);
423 tabIconRect.adjust(+4, +4, -4, -4);
424 tabTextRect.translate(0, -2);
425 QFont boldFont(painter->font());
426 boldFont.setPointSizeF(Utils::StyleHelper::sidebarFontSize());
427 boldFont.setBold(true);
428 painter->setFont(boldFont);
429 painter->setPen(selected ? QColor(255, 255, 255, 160) : QColor(0, 0, 0, 110));
430 // int textFlags = Qt::AlignCenter | Qt::AlignBottom;
431 // painter->drawText(tabTextRect, textFlags, tabText);
432 painter->setPen(selected ? QColor(60, 60, 60) : Utils::StyleHelper::panelTextColor());
433#ifndef Q_OS_MACOS
434 if (!selected) {
435 painter->save();
436 int fader = int(m_tabs[tabIndex]->fader());
437 QLinearGradient grad(rect.topLeft(), rect.topRight());
438 grad.setColorAt(0, Qt::transparent);
439 grad.setColorAt(0.5, QColor(255, 255, 255, fader));
440 grad.setColorAt(1, Qt::transparent);
441// painter->fillRect(rect, grad);
442// painter->setPen(QPen(grad, 1.0));
443 painter->fillRect(rect, QColor(255, 255, 255, fader));
444 painter->setPen(QPen(QColor(255, 255, 255, fader), 1.0));
445 painter->drawLine(rect.topLeft(), rect.topRight());
446 painter->drawLine(rect.bottomLeft(), rect.bottomRight());
447 painter->restore();
448 }
449#endif
450
451 // const int textHeight = painter->fontMetrics().height();
452 tabIconRect.adjust(0, 6, 0, -6);
453 Utils::StyleHelper::drawIconWithShadow(tabIcon(tabIndex), tabIconRect, painter, selected ? QIcon::Selected : QIcon::Normal);
454
455 painter->translate(0, -1);
456 // painter->drawText(tabTextRect, textFlags, tabText);
457 painter->restore();
458}
459
461{
462 m_currentIndex = index;
463 update();
464 Q_EMIT currentChanged(m_currentIndex);
465}
466
467
469// FancyColorButton
471
472class FALKON_EXPORT FancyColorButton : public QWidget
473{
474public:
475 FancyColorButton(QWidget* parent)
476 : m_parent(parent) {
477 setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
478 }
479
480 void mousePressEvent(QMouseEvent* ev) override {
481 if (ev->modifiers() & Qt::ShiftModifier) {
483 }
484 }
485private:
486 QWidget* m_parent;
487};
488
490// FancyTabWidget
492
494 : QWidget(parent),
495 mode_(Mode_None),
496 tab_bar_(nullptr),
497 stack_(new QStackedLayout),
498 side_widget_(new QWidget),
499 side_layout_(new QVBoxLayout),
500 top_layout_(new QVBoxLayout),
501 use_background_(false),
502 menu_(nullptr),
503 proxy_style_(new FancyTabProxyStyle)
504{
505 side_layout_->setSpacing(0);
506 side_layout_->setContentsMargins(0, 0, 0, 0);
507 side_layout_->addSpacerItem(new QSpacerItem(0, 0, QSizePolicy::Fixed, QSizePolicy::Expanding));
508
509 side_widget_->setLayout(side_layout_);
510 side_widget_->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
511
512 top_layout_->setContentsMargins(0, 0, 0, 0);
513 top_layout_->setSpacing(0);
514 top_layout_->addLayout(stack_);
515
516 auto* main_layout = new QHBoxLayout;
517 main_layout->setContentsMargins(0, 0, 0, 0);
518 main_layout->setSpacing(1);
519 main_layout->addWidget(side_widget_);
520 main_layout->addLayout(top_layout_);
521 setLayout(main_layout);
522}
523
524void FancyTabWidget::AddTab(QWidget* tab, const QIcon &icon, const QString &label)
525{
526 stack_->addWidget(tab);
527 items_ << Item(icon, label);
528}
529
531{
532 items_ << Item(size);
533}
534
535void FancyTabWidget::SetBackgroundPixmap(const QPixmap &pixmap)
536{
537 background_pixmap_ = pixmap;
538 update();
539}
540
542{
543 if (!use_background_) {
544 return;
545 }
546
547 QPainter painter(this);
548
549 QRect rect = side_widget_->rect().adjusted(0, 0, 1, 0);
550 rect = style()->visualRect(layoutDirection(), geometry(), rect);
551 Utils::StyleHelper::verticalGradient(&painter, rect, rect);
552
553 if (!background_pixmap_.isNull()) {
554 QRect pixmap_rect(background_pixmap_.rect());
555 pixmap_rect.moveTo(rect.topLeft());
556
557 while (pixmap_rect.top() < rect.bottom()) {
558 QRect source_rect(pixmap_rect.intersected(rect));
559 source_rect.moveTo(0, 0);
560 painter.drawPixmap(pixmap_rect.topLeft(), background_pixmap_, source_rect);
561 pixmap_rect.moveTop(pixmap_rect.bottom() - 10);
562 }
563 }
564
565 painter.setPen(Utils::StyleHelper::borderColor());
566 painter.drawLine(rect.topRight(), rect.bottomRight());
567
569 painter.setPen(light);
570 painter.drawLine(rect.bottomLeft(), rect.bottomRight());
571}
572
574{
575 return stack_->currentIndex();
576}
577
579{
580 if (auto* bar = qobject_cast<FancyTabBar*>(tab_bar_)) {
581 bar->setCurrentIndex(index);
582 }
583 else if (auto* bar = qobject_cast<QTabBar*>(tab_bar_)) {
584 bar->setCurrentIndex(index);
585 }
586 else {
587 stack_->setCurrentIndex(index);
588 }
589}
590
591void FancyTabWidget::ShowWidget(int index)
592{
593 stack_->setCurrentIndex(index);
594 Q_EMIT CurrentChanged(index);
595}
596
598{
599 top_layout_->addWidget(widget);
600}
601
603{
604 // Remove previous tab bar
605 delete tab_bar_;
606 tab_bar_ = nullptr;
607
608 use_background_ = false;
609
610 // Create new tab bar
611 switch (mode) {
612 case Mode_None:
613 default:
614 qDebug() << "Unknown fancy tab mode" << mode;
615 // fallthrough
616
617 case Mode_LargeSidebar: {
618 auto* bar = new FancyTabBar(this);
619 side_layout_->insertWidget(0, bar);
620 tab_bar_ = bar;
621
622 for (const Item &item : std::as_const(items_)) {
623 if (item.type_ == Item::Type_Spacer) {
624 bar->addSpacer(item.spacer_size_);
625 }
626 else {
627 bar->addTab(item.tab_icon_, item.tab_label_);
628 }
629 }
630
631 bar->setCurrentIndex(stack_->currentIndex());
632 connect(bar, &FancyTabBar::currentChanged, this, &FancyTabWidget::ShowWidget);
633
634 use_background_ = true;
635
636 break;
637 }
638
639 case Mode_Tabs:
640 MakeTabBar(QTabBar::RoundedNorth, true, false, false);
641 break;
642
644 MakeTabBar(QTabBar::RoundedNorth, false, true, false);
645 break;
646
648 MakeTabBar(QTabBar::RoundedWest, true, true, true);
649 use_background_ = true;
650 break;
651
653 MakeTabBar(QTabBar::RoundedWest, true, true, false);
654 break;
655 }
656
657 tab_bar_->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
658
659 mode_ = mode;
660 Q_EMIT ModeChanged(mode);
661 update();
662}
663
664void FancyTabWidget::contextMenuEvent(QContextMenuEvent* e)
665{
666 Q_UNUSED(e)
667// if (!menu_) {
668// menu_ = new QMenu(this);
669
670// QSignalMapper* mapper = new QSignalMapper(this);
671// QActionGroup* group = new QActionGroup(this);
672// AddMenuItem(mapper, group, tr("Large sidebar"), Mode_LargeSidebar);
673// AddMenuItem(mapper, group, tr("Small sidebar"), Mode_SmallSidebar);
674// AddMenuItem(mapper, group, tr("Plain sidebar"), Mode_PlainSidebar);
675// AddMenuItem(mapper, group, tr("Tabs on top"), Mode_Tabs);
676// AddMenuItem(mapper, group, tr("Icons on top"), Mode_IconOnlyTabs);
677// menu_->addActions(group->actions());
678
679// connect(mapper, SIGNAL(mapped(int)), SLOT(SetMode(int)));
680// }
681
682// menu_->popup(e->globalPos());
683}
684
685void FancyTabWidget::AddMenuItem(QSignalMapper* mapper, QActionGroup* group,
686 const QString &text, Mode mode)
687{
688 QAction* action = group->addAction(text);
689 action->setCheckable(true);
690 mapper->setMapping(action, mode);
691 connect(action, SIGNAL(triggered()), mapper, SLOT(map()));
692
693 if (mode == mode_) {
694 action->setChecked(true);
695 }
696}
697
698void FancyTabWidget::MakeTabBar(QTabBar::Shape shape, bool text, bool icons,
699 bool fancy)
700{
701 auto* bar = new QTabBar(this);
702 bar->setShape(shape);
703 bar->setDocumentMode(true);
704 bar->setUsesScrollButtons(true);
705
706 if (shape == QTabBar::RoundedWest) {
707 bar->setIconSize(QSize(22, 22));
708 }
709
710 if (fancy) {
711 bar->setStyle(proxy_style_);
712 }
713
714 if (shape == QTabBar::RoundedNorth) {
715 top_layout_->insertWidget(0, bar);
716 }
717 else {
718 side_layout_->insertWidget(0, bar);
719 }
720
721 for (const Item &item : std::as_const(items_)) {
722 if (item.type_ != Item::Type_Tab) {
723 continue;
724 }
725
726 QString label = item.tab_label_;
727 if (shape == QTabBar::RoundedWest) {
728 label = QFontMetrics(font()).elidedText(label, Qt::ElideMiddle, 100);
729 }
730
731 int tab_id = -1;
732 if (icons && text) {
733 tab_id = bar->addTab(item.tab_icon_, label);
734 }
735 else if (icons) {
736 tab_id = bar->addTab(item.tab_icon_, QString());
737 }
738 else if (text) {
739 tab_id = bar->addTab(label);
740 }
741
742 bar->setTabToolTip(tab_id, item.tab_label_);
743 }
744
745 bar->setCurrentIndex(stack_->currentIndex());
746 connect(bar, &QTabBar::currentChanged, this, &FancyTabWidget::ShowWidget);
747 tab_bar_ = bar;
748}
FancyTabBar(QWidget *parent=nullptr)
QIcon tabIcon(int index) const
void paintTab(QPainter *painter, int tabIndex) const
QSize minimumSizeHint() const override
void addTab(const QIcon &icon, const QString &label)
QString tabToolTip(int index) const
QSize sizeHint() const override
void paintEvent(QPaintEvent *event) override
bool validIndex(int index) const
QRect tabRect(int index) const
void mousePressEvent(QMouseEvent *) override
void setTabToolTip(int index, const QString &toolTip)
void setFader(float value)
void enterEvent(QEnterEvent *event) override
void leaveEvent(QEvent *) override
QSize sizeHint() const override
void polish(QWidget *widget) override
bool eventFilter(QObject *o, QEvent *e) override
void AddTab(QWidget *tab, const QIcon &icon, const QString &label)
void SetBackgroundPixmap(const QPixmap &pixmap)
FancyTabWidget(QWidget *parent=nullptr)
void SetMode(FancyTabWidget::Mode mode)
void ModeChanged(FancyTabWidget::Mode mode)
void paintEvent(QPaintEvent *event) override
void contextMenuEvent(QContextMenuEvent *e) override
void AddBottomWidget(QWidget *widget)
void mousePressEvent(QMouseEvent *ev) override
FancyColorButton(QWidget *parent)
static void verticalGradient(QPainter *painter, const QRect &spanRect, const QRect &clipRect, bool lightColored=false)
static qreal sidebarFontSize()
Definition: stylehelper.cpp:51
static QColor borderColor(bool lightColored=false)
static QColor requestedBaseColor()
Definition: stylehelper.h:60
static void setBaseColor(const QColor &color)
static QColor panelTextColor(bool lightColored=false)
Definition: stylehelper.cpp:60
static QColor sidebarHighlight()
Definition: stylehelper.h:67
static void drawIconWithShadow(const QIcon &icon, const QRect &rect, QPainter *p, QIcon::Mode iconMode, int radius=3, const QColor &color=QColor(0, 0, 0, 130), const QPoint &offset=QPoint(1, -2))
int value(const QColor &c)
Definition: colors.cpp:238
QColor light(const QColor &c, int value)
Definition: colors.cpp:184
i
Definition: i18n.py:23
#define FALKON_EXPORT
Definition: qzcommon.h:28
#define QSL(x)
Definition: qzcommon.h:40