Skip to content
This repository has been archived by the owner on Aug 7, 2022. It is now read-only.

Commit

Permalink
Auto Tab orientation
Browse files Browse the repository at this point in the history
  • Loading branch information
nitramr committed Nov 18, 2015
1 parent b14a142 commit f8bb077
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 6 deletions.
25 changes: 24 additions & 1 deletion indigodock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,38 @@ void IndigoDock::init(){

layout->addWidget(m_indigoTab);



}

void IndigoDock::addIndigoPanel(IndigoPanel *panel, int tabIndex){

m_indigoTab->addIndigoPanel(panel, tabIndex );


// Add some invalid content to test exceptions
QWidget * widget = new QWidget();
m_indigoTab->addTab(widget,QIcon(":/icons/icons/placeholder.png") ,"");
m_indigoTab->addTab(widget,QIcon(":/icons/icons/open.png") ,"");


}

void IndigoDock::updateTabWidget(Qt::DockWidgetArea area){

switch(area){
case Qt::LeftDockWidgetArea:{
m_indigoTab->setTabPosition(IndigoTabbar::West);
break;
}
case Qt::RightDockWidgetArea:{
m_indigoTab->setTabPosition(IndigoTabbar::East);
break;
}
default:

break;

}

}

Expand Down
1 change: 1 addition & 0 deletions indigodock.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class IndigoDock : public QWidget
signals:

public slots:
void updateTabWidget(Qt::DockWidgetArea area);
};

#endif // INDIGODOCK_H
52 changes: 48 additions & 4 deletions indigotabbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ void IndigoTabbar::addIndigoPanel(IndigoPanel *panel, int tabIndex ){
QWidget * widget = this->widget(tabIndex);

IndigoDropZone *zone = qobject_cast<IndigoDropZone*>(widget);

if(!zone) return;

zone->addPanel(panel);
Expand All @@ -116,13 +115,33 @@ void IndigoTabbar::setActiveTab(int index){
}


void IndigoTabbar::setTabPosition(TabPosition tabPos){


// Rotate icons in right direction
for(int i=0;i<count();i++)
{
QIcon icon = this->tabBar()->tabIcon(i);

icon = rotateIcon(icon, tabPos);

this->tabBar()->setTabIcon(i, icon);

}

// set new tab position
QTabWidget::setTabPosition(tabPos);

}


/******************
*
* Helper
*
* ***************/

QIcon IndigoTabbar::rotateIcon(const QIcon &icon){
QIcon IndigoTabbar::rotateIcon(const QIcon &icon, TabPosition tabPos){

QSize sz;

Expand All @@ -135,11 +154,36 @@ QIcon IndigoTabbar::rotateIcon(const QIcon &icon){

switch(this->tabPosition()){
case QTabWidget::East:{
trans.rotate(-90);
switch(tabPos){
case QTabWidget::West:{
trans.rotate(180);
break;
}
case QTabWidget::North:{
trans.rotate(-90);
break;
}
default:
break;
}


break;
}
case QTabWidget::West:{
trans.rotate(+90);
switch(tabPos){

case QTabWidget::East:{
trans.rotate(180);
break;
}
case QTabWidget::North:{
trans.rotate(+90);
break;
}
default:
break;
}
break;
}
default:
Expand Down
4 changes: 3 additions & 1 deletion indigotabbar.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ class IndigoTabbar : public QTabWidget
void addTab ( QWidget * child, const QString & label );
void addTab ( QWidget * child, const QIcon & icon, const QString & label );
void addIndigoPanel(IndigoPanel *panel, int tabIndex = -1 );
void setTabPosition(TabPosition tabPos);
QWidget * m_activeWidget;

protected:
QIcon rotateIcon(const QIcon &icon);
QIcon rotateIcon(const QIcon &icon, TabPosition tabPos = QTabWidget::North);

private:
int iconScale;

Expand Down
3 changes: 3 additions & 0 deletions mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ MainWindow::MainWindow(QWidget *parent) :
// TabWidget
IndigoDock *indigoDock_r = new IndigoDock;


// Container
m_mainLayout_r = new QGridLayout();
m_mainLayout_r->setMargin(0);
Expand All @@ -53,6 +54,7 @@ MainWindow::MainWindow(QWidget *parent) :

// set Layouted Widget to DockPanel
m_dockright->setWidget(containerRight);
connect(m_dockright, SIGNAL(dockLocationChanged(Qt::DockWidgetArea)), indigoDock_r, SLOT(updateTabWidget(Qt::DockWidgetArea)));



Expand All @@ -69,6 +71,7 @@ MainWindow::MainWindow(QWidget *parent) :

// set Layouted Widget to DockPanel
m_dockleft->setWidget(containerLeft);
connect(m_dockleft, SIGNAL(dockLocationChanged(Qt::DockWidgetArea)), indigoDock_l, SLOT(updateTabWidget(Qt::DockWidgetArea)));



Expand Down

0 comments on commit f8bb077

Please sign in to comment.