File indexing completed on 2024-04-28 04:55:39

0001 /*
0002     This file is part of Choqok, the KDE micro-blogging client
0003 
0004     SPDX-FileCopyrightText: 2011-2012 Mehrdad Momeny <mehrdad.momeny@gmail.com>
0005     SPDX-FileCopyrightText: 2011-2012 Bardia Daneshvar <bardia.daneshvar@gmail.com>
0006 
0007     SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0008 */
0009 
0010 #include "choqoktabbar.h"
0011 
0012 #include <QAction>
0013 #include <QGridLayout>
0014 #include <QHash>
0015 #include <QList>
0016 #include <QMenu>
0017 #include <QResizeEvent>
0018 #include <QStackedWidget>
0019 #include <QToolBar>
0020 
0021 #include "choqokappearancesettings.h"
0022 
0023 #define ICON_SMALL_SIZE  22
0024 #define ICON_MEDIUM_SIZE 32
0025 #define ICON_BIG_SIZE    40
0026 
0027 namespace Choqok
0028 {
0029 namespace UI
0030 {
0031 
0032 QList<ChoqokTabBar *> choqok_tabbars_list;
0033 
0034 class ChoqokTabBarPrivate
0035 {
0036 public:
0037     QToolBar *toolbar;
0038     QStackedWidget *st_widget;
0039 //     QWidget *tab_widget;
0040     QWidget *tab_alongside_widget;
0041 
0042     QGridLayout *main_layout;
0043     QGridLayout *stack_wgt_layout;
0044 
0045     ChoqokTabBar::TabPosition       position;
0046     ChoqokTabBar::SelectionBehavior selection_behavior;
0047     bool tab_closable;
0048     bool styled_tabbar;
0049 
0050     QHash<Qt::Corner, QWidget *> corners_hash;
0051     QHash<ChoqokTabBar::ExtraWidgetPosition, QWidget *> extra_wgt_hash;
0052 
0053     QList<QAction *> actions_list;
0054     QList<int> history_list;
0055 
0056     QPalette old_palette;
0057 };
0058 
0059 ChoqokTabBar::ChoqokTabBar(QWidget *parent) :
0060     QWidget(parent)
0061 {
0062     p = new ChoqokTabBarPrivate;
0063     p->position = (TabPosition)Choqok::AppearanceSettings::tabBarPosition();
0064     p->styled_tabbar = Choqok::AppearanceSettings::tabBarIsStyled();
0065     p->tab_alongside_widget = nullptr;
0066     p->tab_closable = false;
0067     p->selection_behavior = ChoqokTabBar::SelectPreviousTab;
0068 
0069 //     p->tab_widget = new QWidget();
0070     p->st_widget = new QStackedWidget();
0071     p->toolbar = new QToolBar();
0072     p->toolbar->setContextMenuPolicy(Qt::CustomContextMenu);
0073 
0074     p->stack_wgt_layout = new QGridLayout();
0075     p->stack_wgt_layout->addWidget(p->st_widget , 1 , 1);
0076     p->stack_wgt_layout->setContentsMargins(0 , 0 , 0 , 0);
0077 
0078     p->main_layout = new QGridLayout(this);
0079     p->main_layout->setSpacing(0);
0080     p->main_layout->setContentsMargins(0 , 0 , 0 , 0);
0081     p->main_layout->addLayout(p->stack_wgt_layout , 1 , 1);
0082 
0083     connect(p->toolbar, &QToolBar::actionTriggered, this, &ChoqokTabBar::action_triggered);
0084     connect(p->toolbar, &QToolBar::customContextMenuRequested, this, &ChoqokTabBar::contextMenuRequest);
0085 
0086     setToolButtonStyle(Qt::ToolButtonIconOnly);
0087     int iconSize = Choqok::AppearanceSettings::tabBarSize();
0088     if (iconSize != ICON_BIG_SIZE && iconSize != ICON_MEDIUM_SIZE && iconSize != ICON_SMALL_SIZE) {
0089         iconSize = ICON_MEDIUM_SIZE;
0090     }
0091 
0092     init_position(p->position);
0093     setIconSize(QSize(iconSize, iconSize));
0094     init_style();
0095 }
0096 
0097 void ChoqokTabBar::setTabPosition(ChoqokTabBar::TabPosition position)
0098 {
0099     if (position == p->position) {
0100         return;
0101     }
0102 
0103     p->main_layout->removeWidget(p->toolbar);
0104 
0105     init_position(position);
0106     init_style();
0107     init_alongside_widget(size());
0108 
0109     /*! ----------- Setting Up All Linked ChoqokTabBars ------------ */
0110     if (linkedTabBar())
0111         for (int i = 0 ; i < choqok_tabbars_list.count() ; i++) {
0112             choqok_tabbars_list.at(i)->setTabPosition(position);
0113         }
0114     /*! ------------------------------------------------------------ */
0115 
0116     Q_EMIT tabPositionChanged(position);
0117 }
0118 
0119 void ChoqokTabBar::init_position(ChoqokTabBar::TabPosition position)
0120 {
0121     p->position = position;
0122 
0123     /*! ---------- Adding to the New Layout -------------- */
0124     switch (static_cast<int>(position)) {
0125     case ChoqokTabBar::North :
0126         p->main_layout->addWidget(p->toolbar , 0 , 1);
0127         p->toolbar->setOrientation(Qt::Horizontal);
0128         p->toolbar->setSizePolicy(QSizePolicy::MinimumExpanding , QSizePolicy::Minimum);
0129         break;
0130 
0131     case ChoqokTabBar::South :
0132         p->main_layout->addWidget(p->toolbar , 2 , 1);
0133         p->toolbar->setOrientation(Qt::Horizontal);
0134         p->toolbar->setSizePolicy(QSizePolicy::MinimumExpanding , QSizePolicy::Minimum);
0135         break;
0136 
0137     case ChoqokTabBar::West :
0138         p->main_layout->addWidget(p->toolbar , 1 , 0);
0139         p->toolbar->setOrientation(Qt::Vertical);
0140         p->toolbar->setSizePolicy(QSizePolicy::Minimum , QSizePolicy::MinimumExpanding);
0141         break;
0142 
0143     case ChoqokTabBar::East :
0144         p->main_layout->addWidget(p->toolbar , 1 , 2);
0145         p->toolbar->setOrientation(Qt::Vertical);
0146         p->toolbar->setSizePolicy(QSizePolicy::Minimum , QSizePolicy::MinimumExpanding);
0147         break;
0148     }
0149 }
0150 
0151 ChoqokTabBar::TabPosition ChoqokTabBar::tabPosition() const
0152 {
0153     return p->position;
0154 }
0155 
0156 void ChoqokTabBar::setTabsClosable(bool closeable)
0157 {
0158     if (p->tab_closable == closeable) {
0159         return;
0160     }
0161 
0162     p->tab_closable = closeable;
0163 
0164     /*! ----------- Setting Up All Linked ChoqokTabBars ------------ */
0165     if (linkedTabBar())
0166         for (int i = 0 ; i < choqok_tabbars_list.count() ; i++) {
0167             choqok_tabbars_list.at(i)->setTabsClosable(closeable);
0168         }
0169     /*! ------------------------------------------------------------ */
0170 }
0171 
0172 bool ChoqokTabBar::tabsClosable() const
0173 {
0174     return p->tab_closable;
0175 }
0176 
0177 void ChoqokTabBar::setCornerWidget(QWidget *w , Qt::Corner corner)
0178 {
0179     if (p->corners_hash.contains(corner)) {
0180         return;
0181     }
0182 
0183     p->corners_hash.insert(corner , w);
0184 }
0185 
0186 QWidget *ChoqokTabBar::cornerWidget(Qt::Corner corner) const
0187 {
0188     return p->corners_hash.value(corner);
0189 }
0190 
0191 void ChoqokTabBar::setExtraWidget(QWidget *widget , ChoqokTabBar::ExtraWidgetPosition position)
0192 {
0193     if (p->extra_wgt_hash.contains(position)) {
0194         p->extra_wgt_hash.remove(position);
0195     }
0196 
0197     if (p->extra_wgt_hash.values().contains(widget)) {
0198         p->extra_wgt_hash.remove(p->extra_wgt_hash.key(widget));
0199     }
0200 
0201     switch (static_cast<int>(position)) {
0202     case ChoqokTabBar::Top :
0203         p->stack_wgt_layout->addWidget(widget , 0 , 1);
0204         break;
0205 
0206     case ChoqokTabBar::Bottom :
0207         p->stack_wgt_layout->addWidget(widget , 2 , 1);
0208         break;
0209 
0210     case ChoqokTabBar::Left :
0211         p->stack_wgt_layout->addWidget(widget , 1 , 0);
0212         break;
0213 
0214     case ChoqokTabBar::Right :
0215         p->stack_wgt_layout->addWidget(widget , 1 , 2);
0216         break;
0217     }
0218 
0219     p->extra_wgt_hash.insert(position , widget);
0220 
0221     init_extra_widget(size());
0222 }
0223 
0224 QWidget *ChoqokTabBar::extraWidget(ExtraWidgetPosition position)
0225 {
0226     return p->extra_wgt_hash.value(position);
0227 }
0228 
0229 void ChoqokTabBar::setTabAlongsideWidget(QWidget *widget)
0230 {
0231     p->tab_alongside_widget = widget;
0232     init_alongside_widget(size());
0233 }
0234 
0235 QWidget *ChoqokTabBar::tabAlongsideWidget() const
0236 {
0237     return p->tab_alongside_widget;
0238 }
0239 
0240 void ChoqokTabBar::setTabCloseActivatePrevious(bool stt)
0241 {
0242     if (stt) {
0243         setSelectionBehaviorOnRemove(ChoqokTabBar::SelectPreviousTab);
0244     } else {
0245         setSelectionBehaviorOnRemove(ChoqokTabBar::SelectLeftTab);
0246     }
0247 }
0248 
0249 bool ChoqokTabBar::tabCloseActivatePrevious() const
0250 {
0251     return (p->selection_behavior == ChoqokTabBar::SelectPreviousTab);
0252 }
0253 
0254 ChoqokTabBar::SelectionBehavior ChoqokTabBar::selectionBehaviorOnRemove() const
0255 {
0256     return p->selection_behavior;
0257 }
0258 
0259 void ChoqokTabBar::setSelectionBehaviorOnRemove(ChoqokTabBar::SelectionBehavior behavior)
0260 {
0261     if (p->selection_behavior == behavior) {
0262         return;
0263     }
0264 
0265     p->selection_behavior = behavior;
0266 
0267     /*! ----------- Setting Up All Linked ChoqokTabBars ------------ */
0268     if (linkedTabBar())
0269         for (int i = 0 ; i < choqok_tabbars_list.count() ; i++) {
0270             choqok_tabbars_list.at(i)->setSelectionBehaviorOnRemove(behavior);
0271         }
0272     /*! ------------------------------------------------------------ */
0273 }
0274 
0275 QWidget *ChoqokTabBar::currentWidget() const
0276 {
0277     return p->st_widget->currentWidget();
0278 }
0279 
0280 QWidget *ChoqokTabBar::widget(int index) const
0281 {
0282     return p->st_widget->widget(index);
0283 }
0284 
0285 int ChoqokTabBar::currentIndex() const
0286 {
0287     return p->st_widget->currentIndex();
0288 }
0289 
0290 int ChoqokTabBar::indexOf(QWidget *widget) const
0291 {
0292     return p->st_widget->indexOf(widget);
0293 }
0294 
0295 int ChoqokTabBar::addTab(QWidget *widget , const QString &name)
0296 {
0297     return insertTab(count() , widget , QIcon() , name);
0298 }
0299 
0300 int ChoqokTabBar::addTab(QWidget *widget , const QIcon &icon , const QString &name)
0301 {
0302     return insertTab(count() , widget , icon , name);
0303 }
0304 
0305 int ChoqokTabBar::insertTab(int index , QWidget *widget , const QString &name)
0306 {
0307     return insertTab(index , widget , QIcon() , name);
0308 }
0309 
0310 int ChoqokTabBar::insertTab(int index , QWidget *widget , const QIcon &input_icon , const QString &name)
0311 {
0312     QIcon icon(input_icon);
0313     if (input_icon.isNull()) {
0314         icon = QIcon::fromTheme(QLatin1String("edit-find"));
0315     }
0316 
0317     QAction *action = new QAction(icon , name , this);
0318     action->setCheckable(true);
0319 
0320     p->actions_list.insert(index , action);
0321     p->st_widget->insertWidget(index , widget);
0322 
0323     connect(widget, &QWidget::destroyed, this, &ChoqokTabBar::widget_destroyed);
0324 
0325     for (int i = 0 ; i < p->history_list.count() ; i++)
0326         if (p->history_list.at(i) >= index) {
0327             p->history_list[ i ]++;
0328         }
0329 
0330     refreshTabBar();
0331 
0332     if (count() == 1) {
0333         action->trigger();
0334         p->history_list << 0;
0335     }
0336 
0337     return index;
0338 }
0339 
0340 void ChoqokTabBar::moveTab(int from , int to)
0341 {
0342     int low , high;
0343 
0344     if (from == to) {
0345         return ;
0346     }
0347     if (from >  to) {
0348         low = to;
0349         high = from;
0350     } else {
0351         low = from;
0352         high = to;
0353     }
0354 
0355     p->actions_list.move(from , to);
0356     p->st_widget->move(from , to);
0357 
0358     int shift = (from > to) * 2 - 1;
0359     for (int i = 0; i < p->history_list.count() ; i++) {
0360         int index = p->history_list.at(i);
0361         if (index > low && index < high) {
0362             p->history_list[ i ] += shift;
0363         }
0364 
0365         if (index == from) {
0366             p->history_list[ i ] = to;
0367         }
0368     }
0369 
0370     refreshTabBar();
0371     Q_EMIT tabMoved(from , to);
0372 }
0373 
0374 void ChoqokTabBar::removeTab(int index)
0375 {
0376     disconnect(p->st_widget->widget(index), &QWidget::destroyed, this, &ChoqokTabBar::widget_destroyed);
0377 
0378     p->history_list.removeAll(index);
0379     p->actions_list.removeAt(index);
0380     p->st_widget->removeWidget(p->st_widget->widget(index));
0381 
0382     for (int i = 0 ; i < p->history_list.count() ; i++)
0383         if (p->history_list.at(i) > index) {
0384             p->history_list[ i ]--;
0385         }
0386 
0387     if (!p->history_list.isEmpty()) {
0388         p->actions_list[ p->history_list.takeFirst() ]->trigger();
0389     }
0390 
0391     refreshTabBar();
0392 }
0393 
0394 void ChoqokTabBar::removePage(QWidget *widget)
0395 {
0396     removeTab(p->st_widget->indexOf(widget));
0397 }
0398 
0399 void ChoqokTabBar::setTabIcon(int index , const QIcon &input_icon)
0400 {
0401     p->actions_list[ index ]->setIcon(input_icon);
0402 }
0403 
0404 QIcon ChoqokTabBar::tabIcon(int index) const
0405 {
0406     return p->actions_list.at(index)->icon();
0407 }
0408 
0409 void ChoqokTabBar::setTabText(int index , const QString &text)
0410 {
0411     p->actions_list[ index ]->setText(text);
0412 }
0413 
0414 QString ChoqokTabBar::tabText(int index) const
0415 {
0416     return p->actions_list.at(index)->text();
0417 }
0418 
0419 void ChoqokTabBar::setLinkedTabBar(bool stt)
0420 {
0421     if (linkedTabBar() == stt) {
0422         return;
0423     }
0424 
0425     if (!choqok_tabbars_list.isEmpty() && stt) {
0426         ChoqokTabBar *tmp = choqok_tabbars_list.first();
0427 
0428         setIconSize(tmp->iconSize());
0429         setStyledTabBar(tmp->styledTabBar());
0430         setTabPosition(tmp->tabPosition());
0431         setSelectionBehaviorOnRemove(tmp->selectionBehaviorOnRemove());
0432         setTabsClosable(tmp->tabsClosable());
0433         setToolButtonStyle(tmp->toolButtonStyle());
0434     }
0435 
0436     if (stt) {
0437         choqok_tabbars_list << this;
0438     } else {
0439         choqok_tabbars_list.removeOne(this);
0440     }
0441 }
0442 
0443 bool ChoqokTabBar::linkedTabBar() const
0444 {
0445     for (int i = 0 ; i < choqok_tabbars_list.count() ; i++)
0446         if (choqok_tabbars_list.at(i) == this) {
0447             return true;
0448         }
0449 
0450     return false;
0451 }
0452 
0453 void ChoqokTabBar::setTabBarHidden(bool stt)
0454 {
0455     p->toolbar->setHidden(stt);
0456 }
0457 
0458 bool ChoqokTabBar::isTabBarHidden() const
0459 {
0460     return p->toolbar->isHidden();
0461 }
0462 
0463 QSize ChoqokTabBar::iconSize() const
0464 {
0465     return p->toolbar->iconSize();
0466 }
0467 
0468 void ChoqokTabBar::setIconSize(const QSize &size)
0469 {
0470     if (size == p->toolbar->iconSize()) {
0471         return;
0472     }
0473 
0474     p->toolbar->setIconSize(size);
0475 
0476     /*! ----------- Setting Up All Linked ChoqokTabBars ------------ */
0477     if (linkedTabBar())
0478         for (int i = 0 ; i < choqok_tabbars_list.count() ; i++) {
0479             choqok_tabbars_list.at(i)->setIconSize(size);
0480         }
0481     /*! ------------------------------------------------------------ */
0482 
0483     Q_EMIT iconSizeChanged(size);
0484 }
0485 
0486 int ChoqokTabBar::count() const
0487 {
0488     return p->st_widget->count();
0489 }
0490 
0491 Qt::ToolButtonStyle ChoqokTabBar::toolButtonStyle() const
0492 {
0493     return p->toolbar->toolButtonStyle();
0494 }
0495 
0496 void ChoqokTabBar::setToolButtonStyle(Qt::ToolButtonStyle toolButtonStyle)
0497 {
0498     if (p->toolbar->toolButtonStyle() == toolButtonStyle) {
0499         return;
0500     }
0501 
0502     p->toolbar->setToolButtonStyle(toolButtonStyle);
0503 
0504     /*! ----------- Setting Up All Linked ChoqokTabBars ------------ */
0505     if (linkedTabBar())
0506         for (int i = 0 ; i < choqok_tabbars_list.count() ; i++) {
0507             choqok_tabbars_list.at(i)->setToolButtonStyle(toolButtonStyle);
0508         }
0509     /*! ------------------------------------------------------------ */
0510 }
0511 
0512 void ChoqokTabBar::setStyledTabBar(bool stt)
0513 {
0514     if (p->styled_tabbar == stt) {
0515         return;
0516     }
0517 
0518     p->styled_tabbar = stt;
0519     init_style();
0520 
0521     /*! ----------- Setting Up All Linked ChoqokTabBars ------------ */
0522     if (linkedTabBar())
0523         for (int i = 0 ; i < choqok_tabbars_list.count() ; i++) {
0524             choqok_tabbars_list.at(i)->setStyledTabBar(stt);
0525         }
0526     /*! ------------------------------------------------------------ */
0527 
0528     Q_EMIT styledPanelSignal(stt);
0529 }
0530 
0531 bool ChoqokTabBar::styledTabBar() const
0532 {
0533     return p->styled_tabbar;
0534 }
0535 
0536 void ChoqokTabBar::refreshTabBar()
0537 {
0538     p->toolbar->clear();
0539     for (int i = 0 ; i < p->actions_list.count() ; i++) {
0540         p->toolbar->addAction(p->actions_list.at(i));
0541     }
0542 }
0543 
0544 void ChoqokTabBar::setCurrentIndex(int index)
0545 {
0546     p->actions_list[ index ]->trigger();
0547 }
0548 
0549 void ChoqokTabBar::setCurrentWidget(QWidget *widget)
0550 {
0551     int index = p->st_widget->indexOf(widget);
0552     setCurrentIndex(index);
0553 }
0554 
0555 void ChoqokTabBar::action_triggered(QAction *action)
0556 {
0557     action->setChecked(true);
0558 
0559     int new_index = p->actions_list.indexOf(action);
0560     int old_index = currentIndex();
0561 
0562     if (new_index == old_index) {
0563         return;
0564     }
0565     if (old_index != -1) {
0566         p->actions_list[ old_index ]->setChecked(false);
0567     }
0568 
0569     p->st_widget->setCurrentIndex(new_index);
0570     p->history_list.prepend(new_index);
0571 
0572     Q_EMIT currentChanged(new_index);
0573 }
0574 
0575 void ChoqokTabBar::init_style()
0576 {
0577     if (!styledTabBar()) {
0578         p->toolbar->setStyleSheet(QString());
0579         return;
0580     }
0581 
0582     /*! ----------------- Setup Colors -------------------- */
0583 
0584     QColor tmp = palette().color(QPalette::Active , QPalette::WindowText);
0585     QString highlight_back(QLatin1String("rgba(%1,%2,%3,%4)"));
0586     highlight_back = highlight_back.arg(QString::number(tmp.red()) , QString::number(tmp.green()) , QString::number(tmp.blue()) , QLatin1String("113"));
0587 
0588     tmp = palette().color(QPalette::Active , QPalette::WindowText);
0589     QString shadow(QLatin1String("rgba(%1,%2,%3,%4)"));
0590     shadow = shadow.arg(QString::number(tmp.red()) , QString::number(tmp.green()) , QString::number(tmp.blue()) , QLatin1String("173"));
0591 
0592     tmp = palette().color(QPalette::Active , QPalette::Highlight);
0593     tmp.setHsv(tmp.hue() , tmp.saturation() , tmp.value() / 2);
0594     QString alt_highlight(QLatin1String("rgba(%1,%2,%3,%4)"));
0595     alt_highlight = alt_highlight.arg(QString::number(tmp.red()) , QString::number(tmp.green()) , QString::number(tmp.blue()) , QLatin1String("255"));
0596 
0597     /*! -------------------------------------------------- */
0598 
0599     p->old_palette = palette();
0600     switch (static_cast<int>(tabPosition())) {
0601     case ChoqokTabBar::North :
0602         p->toolbar->setStyleSheet(
0603             QLatin1String("QToolBar{ "
0604             "background-color: qlineargradient(spread:pad, x1:0, y1:1, x2:0, y2:0, stop:0 ") + shadow + QLatin1String(", stop:0.10 ") + alt_highlight + QLatin1String(","
0605             " stop:0.90 palette(highlight), stop:1 ") + shadow + QLatin1String(");"
0606             "border-style: solid;"
0607             "padding: 0px}"
0608 
0609             "QToolButton{ border-style:solid; background-color: transparent;"
0610             "padding-left:   2px;"
0611             "padding-right:  2px;"
0612             "padding-top:    6px;"
0613             "padding-bottom: 6px;"
0614             "margin: 0px; }"
0615             "QToolButton:checked{ background-color: qconicalgradient(cx:0.5, cy:0.85, angle:90, stop:0 transparent, stop:0.3500 ") + highlight_back +
0616             QLatin1String(", stop:0.3700 palette(window), stop:0.6500 palette(window), stop:0.6700 ") + highlight_back + QLatin1String(", stop:1 transparent); }"
0617             "QToolButton:hover:!checked{ background-color: qlineargradient(x1:0, y1:3, x2:0, y2:0, stop:0 ") + shadow + QLatin1String(",stop:1 transparent); }")
0618         );
0619         break;
0620     case ChoqokTabBar::South :
0621         p->toolbar->setStyleSheet(
0622             QLatin1String("QToolBar{ "
0623             "background-color: qlineargradient(spread:pad, x1:0, y1:1, x2:0, y2:0, stop:0 ") + shadow + QLatin1String(", stop:0.10 palette(highlight),"
0624             " stop:0.90 ") + alt_highlight + QLatin1String(", stop:1 ") + shadow + QLatin1String(");"
0625             "border-style: solid;"
0626             "padding: 0px}"
0627 
0628             "QToolButton{ border-style:solid; background-color: transparent;"
0629             "padding-left:   2px;"
0630             "padding-right:  2px;"
0631             "padding-top:    6px;"
0632             "padding-bottom: 6px;"
0633             "margin: 0px; }"
0634             "QToolButton:checked{ background-color: qconicalgradient(cx:0.5, cy:0.15, angle:270, stop:0 transparent, stop:0.3500 ") + highlight_back +
0635             QLatin1String(", stop:0.3700 palette(window), stop:0.6500 palette(window), stop:0.6700 ") + highlight_back + QLatin1String(", stop:1 transparent); }"
0636             "QToolButton:hover:!checked{ background-color: qlineargradient(x1:0, y1:-2, x2:0, y2:1, stop:0 ") + shadow + QLatin1String(",stop:1 transparent); }")
0637         );
0638         break;
0639     case ChoqokTabBar::West :
0640         p->toolbar->setStyleSheet(
0641             QLatin1String("QToolBar{ "
0642             "background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, stop:0 ") + alt_highlight + QLatin1String(", stop:0.90 palette(highlight), "
0643             "stop:1 ") + shadow + QLatin1String(");"
0644             "border-style: solid;"
0645             "padding: 0px}"
0646 
0647             "QToolButton{ border-style:solid; background-color: transparent;"
0648             "padding-left:   6px;"
0649             "padding-right:  6px;"
0650             "padding-top:    2px;"
0651             "padding-bottom: 2px;"
0652             "margin: 0px; }"
0653             "QToolButton:checked{ background-color: qconicalgradient(cx:0.85, cy:0.5, angle:180, stop:0 transparent, stop:0.3500 ") + highlight_back +
0654             QLatin1String(", stop:0.3700 palette(window), stop:0.6500 palette(window), stop:0.6700 ") + highlight_back + QLatin1String(", stop:1 transparent); }"
0655             "QToolButton:hover:!checked{ background-color: qlineargradient(x1:3, y1:0, x2:0, y2:0, stop:0 ") + shadow + QLatin1String(",stop:1 transparent); }")
0656         );
0657         break;
0658     case ChoqokTabBar::East :
0659         p->toolbar->setStyleSheet(
0660             QLatin1String("QToolBar{ "
0661             "background-color: qlineargradient(spread:pad, x1:1, y1:0, x2:0, y2:0, stop:0 ") + alt_highlight + QLatin1String(", stop:0.90 palette(highlight), "
0662             "stop:1 ") + shadow + QLatin1String(");"
0663             "border-style: solid;"
0664             "padding: 0px}"
0665 
0666             "QToolButton{ border-style:solid; background-color: transparent;"
0667             "padding-left:   6px;"
0668             "padding-right:  6px;"
0669             "padding-top:    2px;"
0670             "padding-bottom: 2px;"
0671             "margin: 0px; }"
0672             "QToolButton:checked{ background-color: qconicalgradient(cx:0.15, cy:0.5, angle:0, stop:0 transparent, stop:0.3500 ") + highlight_back +
0673             QLatin1String(", stop:0.3700 palette(window), stop:0.6500 palette(window), stop:0.6700 ") + highlight_back + QLatin1String(", stop:1 transparent); }"
0674             "QToolButton:hover:!checked{ background-color: qlineargradient(x1:-2, y1:0, x2:1, y2:0, stop:0 ") + shadow + QLatin1String(",stop:1 transparent); }")
0675         );
0676         break;
0677     }
0678 }
0679 
0680 void ChoqokTabBar::init_extra_widget(const QSize &size)
0681 {
0682     QWidget *widget;
0683 
0684     if (p->corners_hash.contains(Qt::TopLeftCorner)) {
0685         widget = p->corners_hash.value(Qt::TopLeftCorner);
0686         widget->move(0 , 0);
0687     }
0688 
0689     if (p->corners_hash.contains(Qt::TopRightCorner)) {
0690         widget = p->corners_hash.value(Qt::TopRightCorner);
0691         widget->move(size.width() - widget->width() , 0);
0692     }
0693 
0694     if (p->corners_hash.contains(Qt::BottomLeftCorner)) {
0695         widget = p->corners_hash.value(Qt::BottomLeftCorner);
0696         widget->move(0 , size.height() - widget->height());
0697     }
0698 
0699     if (p->corners_hash.contains(Qt::BottomRightCorner)) {
0700         widget = p->corners_hash.value(Qt::BottomRightCorner);
0701         widget->move(size.width() - widget->width() , size.height() - widget->height());
0702     }
0703 }
0704 
0705 void ChoqokTabBar::init_alongside_widget(const QSize &size)
0706 {
0707     if (!p->tab_alongside_widget) {
0708         return;
0709     }
0710 
0711     QWidget *widget = p->tab_alongside_widget;
0712     switch (static_cast<int>(tabPosition())) {
0713     case North :
0714         widget->move(size.width() - widget->width() , 0);
0715         break;
0716 
0717     case South :
0718         widget->move(size.width() - widget->width() , size.height() - widget->height());
0719         break;
0720 
0721     case West :
0722         widget->move(0 , size.height() - widget->height());
0723         break;
0724 
0725     case East :
0726         widget->move(size.width() - widget->width() , size.height() - widget->height());
0727         break;
0728     }
0729 }
0730 
0731 void ChoqokTabBar::resizeEvent(QResizeEvent *event)
0732 {
0733     QWidget::resizeEvent(event);
0734     init_extra_widget(event->size());
0735     init_alongside_widget(event->size());
0736 }
0737 
0738 void ChoqokTabBar::paintEvent(QPaintEvent *)
0739 {
0740     if (p->old_palette != palette()) {
0741         init_style();
0742     }
0743 }
0744 
0745 void ChoqokTabBar::contextMenuRequest(const QPoint &)
0746 {
0747     const QPoint &global_point = QCursor::pos();
0748     const QPoint &local_point  = mapFromGlobal(global_point);
0749 
0750     QAction *action = p->toolbar->actionAt(local_point);
0751     if (action) {
0752         Q_EMIT contextMenu(global_point);
0753         Q_EMIT contextMenu(widget(p->actions_list.indexOf(action)) , global_point);
0754         return;
0755     }
0756 
0757     QAction north(i18n("Top") , this);
0758     QAction west(i18n("Left")  , this);
0759     QAction east(i18n("Right")  , this);
0760     QAction south(i18n("Bottom") , this);
0761     QAction size_s(i18n("Small")  , this);
0762     QAction size_m(i18n("Medium") , this);
0763     QAction size_b(i18n("Big")    , this);
0764     QAction styled(i18n("Styled Panel") , this);
0765 
0766     /*! ------------- Setting Up Data --------------- */
0767     north.setData(ChoqokTabBar::North);
0768     west.setData(ChoqokTabBar::West);
0769     east.setData(ChoqokTabBar::East);
0770     south.setData(ChoqokTabBar::South);
0771 
0772     size_s.setData(ICON_SMALL_SIZE);
0773     size_m.setData(ICON_MEDIUM_SIZE);
0774     size_b.setData(ICON_BIG_SIZE);
0775     /*! ------------------------------------------------ */
0776 
0777     /*! ------------- Setting Up Actions --------------- */
0778     north.setCheckable(true);
0779     west.setCheckable(true);
0780     east.setCheckable(true);
0781     south.setCheckable(true);
0782     size_s.setCheckable(true);
0783     size_m.setCheckable(true);
0784     size_b.setCheckable(true);
0785     styled.setCheckable(true);
0786     /*! ------------------------------------------------ */
0787 
0788     /*! ------------- Setting Up Checks --------------- */
0789     switch (static_cast<int>(tabPosition())) {
0790     case ChoqokTabBar::North :
0791         north.setChecked(true);
0792         break;
0793     case ChoqokTabBar::South :
0794         south.setChecked(true);
0795         break;
0796     case ChoqokTabBar::West :
0797         west.setChecked(true);
0798         break;
0799     case ChoqokTabBar::East :
0800         east.setChecked(true);
0801         break;
0802     }
0803 
0804     if (iconSize() == QSize(ICON_SMALL_SIZE, ICON_SMALL_SIZE)) {
0805         size_s.setChecked(true);
0806     } else if (iconSize() == QSize(ICON_MEDIUM_SIZE, ICON_MEDIUM_SIZE)) {
0807         size_m.setChecked(true);
0808     } else if (iconSize() == QSize(ICON_BIG_SIZE, ICON_BIG_SIZE)) {
0809         size_b.setChecked(true);
0810     }
0811 
0812     styled.setChecked(styledTabBar());
0813     /*! ------------------------------------------------ */
0814 
0815     QMenu menu;
0816     menu.addAction(&north);
0817     menu.addAction(&west);
0818     menu.addAction(&east);
0819     //menu.addAction( &south   );
0820     menu.addSeparator();
0821     menu.addAction(&size_s);
0822     menu.addAction(&size_m);
0823     menu.addAction(&size_b);
0824     menu.addSeparator();
0825     menu.addAction(&styled);
0826 
0827     QAction *result = menu.exec(global_point);
0828     if (!result) {
0829         return;
0830     }
0831 
0832     else if (result == &styled) {
0833         setStyledTabBar(result->isChecked());
0834     }
0835 
0836     else if (result == &size_s || result == &size_m || result == &size_b) {
0837         setIconSize(QSize(result->data().toInt() , result->data().toInt()));
0838     } else {
0839         setTabPosition(static_cast<ChoqokTabBar::TabPosition>(result->data().toInt()));
0840     }
0841 }
0842 
0843 void ChoqokTabBar::widget_destroyed(QObject *obj)
0844 {
0845     removePage(static_cast<QWidget *>(obj));
0846 }
0847 
0848 ChoqokTabBar::~ChoqokTabBar()
0849 {
0850     Choqok::AppearanceSettings::setTabBarPosition(tabPosition());
0851     Choqok::AppearanceSettings::setTabBarSize(iconSize().width());
0852     Choqok::AppearanceSettings::setTabBarIsStyled(p->styled_tabbar);
0853     Choqok::AppearanceSettings::self()->save();
0854     setLinkedTabBar(false);
0855 
0856     for (int i = 0 ; i < p->st_widget->count() ; i++) {
0857         disconnect(p->st_widget->widget(i), &QWidget::destroyed, this, &ChoqokTabBar::widget_destroyed);
0858     }
0859 
0860     delete p;
0861 }
0862 
0863 }
0864 }
0865 
0866 #include "moc_choqoktabbar.cpp"