Commit d822dc73 authored by Anatoly Mihalchenko's avatar Anatoly Mihalchenko

Merge branch 'Sankore-1.40' of github.com:Sankore/Sankore-3.1 into Sankore-1.40

parents 0180df1b 51467d47
...@@ -206,7 +206,9 @@ void UBSettings::init() ...@@ -206,7 +206,9 @@ void UBSettings::init()
appToolBarOrientationVertical = new UBSetting(this, "App", "ToolBarOrientationVertical", false); appToolBarOrientationVertical = new UBSetting(this, "App", "ToolBarOrientationVertical", false);
navigPaletteWidth = new UBSetting(this, "Board", "NavigPaletteWidth", 270); navigPaletteWidth = new UBSetting(this, "Board", "NavigPaletteWidth", 270);
rightLibPaletteWidth = new UBSetting(this, "Board", "RightLibPaletteWidth", 270); rightLibPaletteWidth = new UBSetting(this, "Board", "RightLibPaletteWidth", 270);
rightLibPaletteIsCollapsed = new UBSetting(this,"Board", "RightLibPaletteIsCollapsed",false);
leftLibPaletteWidth = new UBSetting(this, "Board", "LeftLibPaletteWidth",270); leftLibPaletteWidth = new UBSetting(this, "Board", "LeftLibPaletteWidth",270);
leftLibPaletteIsCollapsed = new UBSetting(this,"Board","LeftLibPaletteIsCollapsed",false);
appIsInSoftwareUpdateProcess = new UBSetting(this, "App", "IsInSoftwareUpdateProcess", false); appIsInSoftwareUpdateProcess = new UBSetting(this, "App", "IsInSoftwareUpdateProcess", false);
appLastSessionDocumentUUID = new UBSetting(this, "App", "LastSessionDocumentUUID", ""); appLastSessionDocumentUUID = new UBSetting(this, "App", "LastSessionDocumentUUID", "");
......
...@@ -316,7 +316,9 @@ class UBSettings : public QObject ...@@ -316,7 +316,9 @@ class UBSettings : public QObject
UBSetting* navigPaletteWidth; UBSetting* navigPaletteWidth;
UBSetting* rightLibPaletteWidth; UBSetting* rightLibPaletteWidth;
UBSetting* rightLibPaletteIsCollapsed;
UBSetting* leftLibPaletteWidth; UBSetting* leftLibPaletteWidth;
UBSetting* leftLibPaletteIsCollapsed;
UBSetting* communityUser; UBSetting* communityUser;
UBSetting* communityPsw; UBSetting* communityPsw;
......
...@@ -29,55 +29,55 @@ ...@@ -29,55 +29,55 @@
* \brief The constructor * \brief The constructor
*/ */
UBDockPalette::UBDockPalette(eUBDockPaletteType paletteType, QWidget *parent, const char *name) UBDockPalette::UBDockPalette(eUBDockPaletteType paletteType, QWidget *parent, const char *name)
:QWidget(parent, Qt::FramelessWindowHint | Qt::X11BypassWindowManagerHint) :QWidget(parent, Qt::FramelessWindowHint | Qt::X11BypassWindowManagerHint)
, mOrientation(eUBDockOrientation_Left) , mOrientation(eUBDockOrientation_Left)
, mPreferredWidth(100) , mPreferredWidth(100)
, mPreferredHeight(100) , mPreferredHeight(100)
, mCanResize(false) , mCanResize(false)
, mResized(false) , mResized(false)
, mCollapseWidth(150) , mCollapseWidth(150)
, mLastWidth(-1) , mLastWidth(-1)
, mHTab(0) , mHTab(0)
, mpStackWidget(NULL) , mpStackWidget(NULL)
, mpLayout(NULL) , mpLayout(NULL)
, mCurrentTab(0) , mCurrentTab(0)
, mPaletteType(paletteType) , mPaletteType(paletteType)
, mTabPalette(new UBTabDockPalette(this, parent)) , mTabPalette(new UBTabDockPalette(this, parent))
{ {
setObjectName(name); setObjectName(name);
mpLayout = new QVBoxLayout(); mpLayout = new QVBoxLayout();
setLayout(mpLayout); setLayout(mpLayout);
mpStackWidget = new QStackedWidget(this); mpStackWidget = new QStackedWidget(this);
mpLayout->addWidget(mpStackWidget); mpLayout->addWidget(mpStackWidget);
// clear the tab widgets // clear the tab widgets
mTabWidgets.clear(); mTabWidgets.clear();
// We let 2 pixels in order to keep a small border for the resizing // We let 2 pixels in order to keep a small border for the resizing
setMinimumWidth(0); setMinimumWidth(0);
if (parent) if (parent)
{ {
setAttribute(Qt::WA_NoMousePropagation); setAttribute(Qt::WA_NoMousePropagation);
setAttribute(Qt::WA_TranslucentBackground); setAttribute(Qt::WA_TranslucentBackground);
} }
else else
{ {
// standalone window // standalone window
setAttribute(Qt::WA_TranslucentBackground); setAttribute(Qt::WA_TranslucentBackground);
} }
mBackgroundBrush = QBrush(UBSettings::paletteColor); mBackgroundBrush = QBrush(UBSettings::paletteColor);
// This is the only way to set the background as transparent! // This is the only way to set the background as transparent!
setStyleSheet("QWidget {background-color: transparent}"); setStyleSheet("QWidget {background-color: transparent}");
// Set the position of the tab // Set the position of the tab
onToolbarPosUpdated(); onToolbarPosUpdated();
connect(UBSettings::settings()->appToolBarPositionedAtTop, SIGNAL(changed(QVariant)), this, SLOT(onToolbarPosUpdated())); connect(UBSettings::settings()->appToolBarPositionedAtTop, SIGNAL(changed(QVariant)), this, SLOT(onToolbarPosUpdated()));
connect(UBDownloadManager::downloadManager(), SIGNAL(allDownloadsFinished()), this, SLOT(onAllDownloadsFinished())); connect(UBDownloadManager::downloadManager(), SIGNAL(allDownloadsFinished()), this, SLOT(onAllDownloadsFinished()));
} }
/** /**
...@@ -85,20 +85,20 @@ UBDockPalette::UBDockPalette(eUBDockPaletteType paletteType, QWidget *parent, co ...@@ -85,20 +85,20 @@ UBDockPalette::UBDockPalette(eUBDockPaletteType paletteType, QWidget *parent, co
*/ */
UBDockPalette::~UBDockPalette() UBDockPalette::~UBDockPalette()
{ {
if(NULL != mpStackWidget) if(NULL != mpStackWidget)
{ {
delete mpStackWidget; delete mpStackWidget;
mpStackWidget = NULL; mpStackWidget = NULL;
} }
if(NULL != mpLayout) if(NULL != mpLayout)
{ {
delete mpLayout; delete mpLayout;
mpLayout = NULL; mpLayout = NULL;
} }
if (NULL != mTabPalette) { if (NULL != mTabPalette) {
delete mTabPalette; delete mTabPalette;
mTabPalette = NULL; mTabPalette = NULL;
} }
} }
/** /**
...@@ -107,7 +107,7 @@ UBDockPalette::~UBDockPalette() ...@@ -107,7 +107,7 @@ UBDockPalette::~UBDockPalette()
*/ */
eUBDockOrientation UBDockPalette::orientation() eUBDockOrientation UBDockPalette::orientation()
{ {
return mOrientation; return mOrientation;
} }
/** /**
...@@ -116,19 +116,19 @@ eUBDockOrientation UBDockPalette::orientation() ...@@ -116,19 +116,19 @@ eUBDockOrientation UBDockPalette::orientation()
*/ */
void UBDockPalette::setOrientation(eUBDockOrientation orientation) void UBDockPalette::setOrientation(eUBDockOrientation orientation)
{ {
// Set the size // Set the size
mOrientation = orientation; mOrientation = orientation;
if(orientation == eUBDockOrientation_Left || orientation == eUBDockOrientation_Right) if(orientation == eUBDockOrientation_Left || orientation == eUBDockOrientation_Right)
{ {
setMaximumHeight(parentWidget()->height()); setMaximumHeight(parentWidget()->height());
setMinimumHeight(maximumHeight()); setMinimumHeight(maximumHeight());
} }
else if(orientation == eUBDockOrientation_Top || orientation == eUBDockOrientation_Bottom) else if(orientation == eUBDockOrientation_Top || orientation == eUBDockOrientation_Bottom)
{ {
setMaximumWidth(parentWidget()->width()); setMaximumWidth(parentWidget()->width());
setMinimumWidth(maximumWidth()); setMinimumWidth(maximumWidth());
} }
} }
/** /**
...@@ -137,32 +137,32 @@ void UBDockPalette::setOrientation(eUBDockOrientation orientation) ...@@ -137,32 +137,32 @@ void UBDockPalette::setOrientation(eUBDockOrientation orientation)
*/ */
void UBDockPalette::resizeEvent(QResizeEvent *event) void UBDockPalette::resizeEvent(QResizeEvent *event)
{ {
Q_UNUSED(event); Q_UNUSED(event);
updateMaxWidth(); updateMaxWidth();
if(parentWidget()) if(parentWidget())
{ {
setMinimumHeight(parentWidget()->height()); setMinimumHeight(parentWidget()->height());
} }
// Set the position // Set the position
QPoint origin; QPoint origin;
switch(mOrientation) switch(mOrientation)
{ {
case eUBDockOrientation_Right: case eUBDockOrientation_Right:
origin.setX(parentWidget()->width() - this->width()); origin.setX(parentWidget()->width() - this->width());
origin.setY(0); origin.setY(0);
break; break;
case eUBDockOrientation_Bottom: case eUBDockOrientation_Bottom:
// Not supported yet // Not supported yet
case eUBDockOrientation_Top: case eUBDockOrientation_Top:
// Not supported yet // Not supported yet
case eUBDockOrientation_Left: case eUBDockOrientation_Left:
default: default:
origin.setX(0); origin.setX(0);
origin.setY(0); origin.setY(0);
break; break;
} }
move(origin.x(), origin.y()); move(origin.x(), origin.y());
moveTabs(); moveTabs();
} }
/** /**
...@@ -171,9 +171,9 @@ void UBDockPalette::resizeEvent(QResizeEvent *event) ...@@ -171,9 +171,9 @@ void UBDockPalette::resizeEvent(QResizeEvent *event)
*/ */
void UBDockPalette::enterEvent(QEvent *event) void UBDockPalette::enterEvent(QEvent *event)
{ {
Q_UNUSED(event); Q_UNUSED(event);
// We want to set the cursor as an arrow everytime it enters the palette // We want to set the cursor as an arrow everytime it enters the palette
setCursor(Qt::ArrowCursor); setCursor(Qt::ArrowCursor);
} }
/** /**
...@@ -182,9 +182,9 @@ void UBDockPalette::enterEvent(QEvent *event) ...@@ -182,9 +182,9 @@ void UBDockPalette::enterEvent(QEvent *event)
*/ */
void UBDockPalette::leaveEvent(QEvent *event) void UBDockPalette::leaveEvent(QEvent *event)
{ {
Q_UNUSED(event); Q_UNUSED(event);
// Restore the cursor to its previous shape // Restore the cursor to its previous shape
unsetCursor(); unsetCursor();
} }
/** /**
...@@ -193,38 +193,38 @@ void UBDockPalette::leaveEvent(QEvent *event) ...@@ -193,38 +193,38 @@ void UBDockPalette::leaveEvent(QEvent *event)
*/ */
void UBDockPalette::paintEvent(QPaintEvent *event) void UBDockPalette::paintEvent(QPaintEvent *event)
{ {
Q_UNUSED(event); Q_UNUSED(event);
QPainter painter(this); QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing); painter.setRenderHint(QPainter::Antialiasing);
painter.setPen(Qt::NoPen); painter.setPen(Qt::NoPen);
painter.setBrush(mBackgroundBrush); painter.setBrush(mBackgroundBrush);
QPainterPath path; QPainterPath path;
path.setFillRule(Qt::WindingFill); path.setFillRule(Qt::WindingFill);
int nbTabs = mTabWidgets.size(); int nbTabs = mTabWidgets.size();
if(0 < nbTabs) if(0 < nbTabs)
{ {
// First draw the BIG RECTANGLE (I write it big because the rectangle is big...) // First draw the BIG RECTANGLE (I write it big because the rectangle is big...)
if(mOrientation == eUBDockOrientation_Left) if(mOrientation == eUBDockOrientation_Left)
{ {
path.addRect(0.0, 0.0, width(), height()); path.addRect(0.0, 0.0, width(), height());
} }
else if(mOrientation == eUBDockOrientation_Right) else if(mOrientation == eUBDockOrientation_Right)
{ {
path.addRect(0.0, 0.0, width(), height()); path.addRect(0.0, 0.0, width(), height());
} }
// THEN DRAW THE small tabs (yes, the tabs are small...) // THEN DRAW THE small tabs (yes, the tabs are small...)
if(eUBDockTabOrientation_Up == mTabsOrientation) if(eUBDockTabOrientation_Up == mTabsOrientation)
{ {
mHTab = border(); mHTab = border();
} }
else else
{ {
mHTab = height() - border() - nbTabs*TABSIZE - (nbTabs-1)*tabSpacing(); mHTab = height() - border() - nbTabs*TABSIZE - (nbTabs-1)*tabSpacing();
} }
painter.drawPath(path); painter.drawPath(path);
} }
} }
/** /**
...@@ -233,11 +233,11 @@ void UBDockPalette::paintEvent(QPaintEvent *event) ...@@ -233,11 +233,11 @@ void UBDockPalette::paintEvent(QPaintEvent *event)
*/ */
void UBDockPalette::setBackgroundBrush(const QBrush &brush) void UBDockPalette::setBackgroundBrush(const QBrush &brush)
{ {
if (mBackgroundBrush != brush) if (mBackgroundBrush != brush)
{ {
mBackgroundBrush = brush; mBackgroundBrush = brush;
update(); update();
} }
} }
/** /**
...@@ -246,7 +246,7 @@ void UBDockPalette::setBackgroundBrush(const QBrush &brush) ...@@ -246,7 +246,7 @@ void UBDockPalette::setBackgroundBrush(const QBrush &brush)
*/ */
int UBDockPalette::border() int UBDockPalette::border()
{ {
return 15; return 15;
} }
/** /**
...@@ -255,7 +255,7 @@ int UBDockPalette::border() ...@@ -255,7 +255,7 @@ int UBDockPalette::border()
*/ */
int UBDockPalette::radius() int UBDockPalette::radius()
{ {
return 5; return 5;
} }
/** /**
...@@ -263,7 +263,7 @@ int UBDockPalette::radius() ...@@ -263,7 +263,7 @@ int UBDockPalette::radius()
*/ */
void UBDockPalette::updateMaxWidth() void UBDockPalette::updateMaxWidth()
{ {
// Only the inherited class will overload this method // Only the inherited class will overload this method
} }
/** /**
...@@ -272,7 +272,7 @@ void UBDockPalette::updateMaxWidth() ...@@ -272,7 +272,7 @@ void UBDockPalette::updateMaxWidth()
*/ */
int UBDockPalette::collapseWidth() int UBDockPalette::collapseWidth()
{ {
return mCollapseWidth; return mCollapseWidth;
} }
/** /**
...@@ -280,17 +280,17 @@ int UBDockPalette::collapseWidth() ...@@ -280,17 +280,17 @@ int UBDockPalette::collapseWidth()
*/ */
void UBDockPalette::tabClicked(int tabIndex) void UBDockPalette::tabClicked(int tabIndex)
{ {
// If the current tab is not the clicked one, show its content // If the current tab is not the clicked one, show its content
if(mCurrentTab != tabIndex) if(mCurrentTab != tabIndex)
{ {
showTabWidget(tabIndex); showTabWidget(tabIndex);
} }
// else collapse the palette // else collapse the palette
else else
{ {
toggleCollapseExpand(); toggleCollapseExpand();
} }
mTabPalette->update(); mTabPalette->update();
} }
/** /**
...@@ -299,19 +299,13 @@ void UBDockPalette::tabClicked(int tabIndex) ...@@ -299,19 +299,13 @@ void UBDockPalette::tabClicked(int tabIndex)
*/ */
void UBDockPalette::showTabWidget(int tabIndex) void UBDockPalette::showTabWidget(int tabIndex)
{ {
mpStackWidget->setCurrentIndex(tabIndex); mpStackWidget->setCurrentIndex(tabIndex);
mCurrentTab = tabIndex; mCurrentTab = tabIndex;
// Expand it if collapsed // Update the current tab index
if(mLastWidth != -1) if(NULL != (dynamic_cast<UBDockPaletteWidget*>(mpStackWidget->widget(tabIndex)))){
{ mCrntTabWidget = dynamic_cast<UBDockPaletteWidget*>(mpStackWidget->widget(tabIndex))->name();
toggleCollapseExpand(); }
}
// Update the current tab index
if(NULL != (dynamic_cast<UBDockPaletteWidget*>(mpStackWidget->widget(tabIndex)))){
mCrntTabWidget = dynamic_cast<UBDockPaletteWidget*>(mpStackWidget->widget(tabIndex))->name();
}
} }
...@@ -320,18 +314,12 @@ void UBDockPalette::showTabWidget(int tabIndex) ...@@ -320,18 +314,12 @@ void UBDockPalette::showTabWidget(int tabIndex)
*/ */
void UBDockPalette::toggleCollapseExpand() void UBDockPalette::toggleCollapseExpand()
{ {
if(mLastWidth == -1) if(width() < mCollapseWidth)
{ resize(mLastWidth,height());
// The palette must be collapsed else{
mLastWidth = width(); mLastWidth = width();
resize(0, height()); resize(0,height());
} }
else
{
// The palette will be expanded
resize(mLastWidth, height());
mLastWidth = -1;
}
} }
/** /**
...@@ -340,7 +328,7 @@ void UBDockPalette::toggleCollapseExpand() ...@@ -340,7 +328,7 @@ void UBDockPalette::toggleCollapseExpand()
*/ */
void UBDockPalette::setTabsOrientation(eUBDockTabOrientation orientation) void UBDockPalette::setTabsOrientation(eUBDockTabOrientation orientation)
{ {
mTabsOrientation = orientation; mTabsOrientation = orientation;
} }
/** /**
...@@ -348,17 +336,17 @@ void UBDockPalette::setTabsOrientation(eUBDockTabOrientation orientation) ...@@ -348,17 +336,17 @@ void UBDockPalette::setTabsOrientation(eUBDockTabOrientation orientation)
*/ */
void UBDockPalette::onToolbarPosUpdated() void UBDockPalette::onToolbarPosUpdated()
{ {
// Get the position of the tab // Get the position of the tab
if(UBSettings::settings()->appToolBarPositionedAtTop->get().toBool()) if(UBSettings::settings()->appToolBarPositionedAtTop->get().toBool())
{ {
setTabsOrientation(eUBDockTabOrientation_Up); setTabsOrientation(eUBDockTabOrientation_Up);
} }
else else
{ {
setTabsOrientation(eUBDockTabOrientation_Down); setTabsOrientation(eUBDockTabOrientation_Down);
} }
moveTabs(); moveTabs();
update(); update();
} }
/** /**
...@@ -367,7 +355,7 @@ void UBDockPalette::onToolbarPosUpdated() ...@@ -367,7 +355,7 @@ void UBDockPalette::onToolbarPosUpdated()
*/ */
int UBDockPalette::customMargin() int UBDockPalette::customMargin()
{ {
return 5; return 5;
} }
/** /**
...@@ -376,15 +364,15 @@ int UBDockPalette::customMargin() ...@@ -376,15 +364,15 @@ int UBDockPalette::customMargin()
*/ */
void UBDockPalette::addTab(UBDockPaletteWidget *widget) void UBDockPalette::addTab(UBDockPaletteWidget *widget)
{ {
if(!mTabWidgets.contains(widget) && widget->visibleState()) if(!mTabWidgets.contains(widget) && widget->visibleState())
{ {
widget->setVisible(true); widget->setVisible(true);
mTabWidgets.append(widget); mTabWidgets.append(widget);
mpStackWidget->addWidget(widget); mpStackWidget->addWidget(widget);
mpStackWidget->setCurrentWidget(widget); mpStackWidget->setCurrentWidget(widget);
resizeTabs(); resizeTabs();
update(); update();
} }
} }
/** /**
* \brief Remove the given tab * \brief Remove the given tab
...@@ -392,16 +380,16 @@ void UBDockPalette::addTab(UBDockPaletteWidget *widget) ...@@ -392,16 +380,16 @@ void UBDockPalette::addTab(UBDockPaletteWidget *widget)
*/ */
void UBDockPalette::removeTab(UBDockPaletteWidget* widget) void UBDockPalette::removeTab(UBDockPaletteWidget* widget)
{ {
int nWidget = mTabWidgets.indexOf(widget); int nWidget = mTabWidgets.indexOf(widget);
if( nWidget >= 0 ) if( nWidget >= 0 )
{ {
mpStackWidget->removeWidget(widget); mpStackWidget->removeWidget(widget);
mTabWidgets.remove(nWidget); mTabWidgets.remove(nWidget);
widget->hide(); widget->hide();
update(); update();
} }
resizeTabs(); resizeTabs();
mCurrentTab = qMax(mCurrentTab - 1, 0); mCurrentTab = qMax(mCurrentTab - 1, 0);
} }
/** /**
...@@ -410,7 +398,7 @@ void UBDockPalette::removeTab(UBDockPaletteWidget* widget) ...@@ -410,7 +398,7 @@ void UBDockPalette::removeTab(UBDockPaletteWidget* widget)
*/ */
void UBDockPalette::onResizeRequest(QResizeEvent *event) void UBDockPalette::onResizeRequest(QResizeEvent *event)
{ {
resizeEvent(event); resizeEvent(event);
} }
/** /**
...@@ -419,7 +407,7 @@ void UBDockPalette::onResizeRequest(QResizeEvent *event) ...@@ -419,7 +407,7 @@ void UBDockPalette::onResizeRequest(QResizeEvent *event)
*/ */
int UBDockPalette::tabSpacing() int UBDockPalette::tabSpacing()
{ {
return 2; return 2;
} }
/** /**
...@@ -428,11 +416,11 @@ int UBDockPalette::tabSpacing() ...@@ -428,11 +416,11 @@ int UBDockPalette::tabSpacing()
*/ */
void UBDockPalette::onShowTabWidget(UBDockPaletteWidget* widget) void UBDockPalette::onShowTabWidget(UBDockPaletteWidget* widget)
{ {
if (mRegisteredWidgets.contains(widget)) if (mRegisteredWidgets.contains(widget))
{ {
widget->setVisibleState(true); widget->setVisibleState(true);
addTab(widget); addTab(widget);
} }
} }
/** /**
...@@ -441,11 +429,11 @@ void UBDockPalette::onShowTabWidget(UBDockPaletteWidget* widget) ...@@ -441,11 +429,11 @@ void UBDockPalette::onShowTabWidget(UBDockPaletteWidget* widget)
*/ */
void UBDockPalette::onHideTabWidget(UBDockPaletteWidget* widget) void UBDockPalette::onHideTabWidget(UBDockPaletteWidget* widget)
{ {
if (mRegisteredWidgets.contains(widget)) if (mRegisteredWidgets.contains(widget))
{ {
widget->setVisibleState(false); widget->setVisibleState(false);
removeTab(widget); removeTab(widget);
} }
} }
/** /**
...@@ -453,11 +441,11 @@ void UBDockPalette::onHideTabWidget(UBDockPaletteWidget* widget) ...@@ -453,11 +441,11 @@ void UBDockPalette::onHideTabWidget(UBDockPaletteWidget* widget)
*/ */
void UBDockPalette::connectSignals() void UBDockPalette::connectSignals()
{ {
for(int i=0; i < mRegisteredWidgets.size(); i++) for(int i=0; i < mRegisteredWidgets.size(); i++)
{ {
connect(mRegisteredWidgets.at(i), SIGNAL(showTab(UBDockPaletteWidget*)), this, SLOT(onShowTabWidget(UBDockPaletteWidget*))); connect(mRegisteredWidgets.at(i), SIGNAL(showTab(UBDockPaletteWidget*)), this, SLOT(onShowTabWidget(UBDockPaletteWidget*)));
connect(mRegisteredWidgets.at(i), SIGNAL(hideTab(UBDockPaletteWidget*)), this, SLOT(onHideTabWidget(UBDockPaletteWidget*))); connect(mRegisteredWidgets.at(i), SIGNAL(hideTab(UBDockPaletteWidget*)), this, SLOT(onHideTabWidget(UBDockPaletteWidget*)));
} }
} }
/** /**
...@@ -466,194 +454,194 @@ void UBDockPalette::connectSignals() ...@@ -466,194 +454,194 @@ void UBDockPalette::connectSignals()
*/ */
void UBDockPalette::registerWidget(UBDockPaletteWidget *widget) void UBDockPalette::registerWidget(UBDockPaletteWidget *widget)
{ {
if(!mRegisteredWidgets.contains(widget)) if(!mRegisteredWidgets.contains(widget))
{ {
// Update the parent of this widget // Update the parent of this widget
widget->setParent(this); widget->setParent(this);
mRegisteredWidgets.append(widget); mRegisteredWidgets.append(widget);
// By default, the widget is hidden // By default, the widget is hidden
widget->hide(); widget->hide();
} }
} }
/** /**
* \brief Handles the 'all download finished' notification * \brief Handles the 'all download finished' notification
*/ */
void UBDockPalette::onAllDownloadsFinished() void UBDockPalette::onAllDownloadsFinished()
{ {
for(int i=0; i<mTabWidgets.size(); i++){ for(int i=0; i<mTabWidgets.size(); i++){
UBDockPaletteWidget* pW = mTabWidgets.at(i); UBDockPaletteWidget* pW = mTabWidgets.at(i);
if(NULL != pW && mCrntTabWidget == pW->name()){ if(NULL != pW && mCrntTabWidget == pW->name()){
mpStackWidget->setCurrentWidget(pW); mpStackWidget->setCurrentWidget(pW);
} }
} }
} }
void UBDockPalette::moveTabs() void UBDockPalette::moveTabs()
{ {
// if (!mHTab) { // if (!mHTab) {
if(eUBDockTabOrientation_Up == mTabsOrientation) { if(eUBDockTabOrientation_Up == mTabsOrientation) {
mHTab = border(); mHTab = border();
} else { } else {
mHTab = height() - border() - mTabWidgets.size() * TABSIZE - (mTabWidgets.size() - 1) * tabSpacing(); mHTab = height() - border() - mTabWidgets.size() * TABSIZE - (mTabWidgets.size() - 1) * tabSpacing();
} }
// } // }
QPoint origin(width(), mHTab + mTabPalette->mVerticalOffset); QPoint origin(width(), mHTab + mTabPalette->mVerticalOffset);
switch (mOrientation) { switch (mOrientation) {
case eUBDockOrientation_Left: case eUBDockOrientation_Left:
origin.setX(width()); origin.setX(width());
break; break;
case eUBDockOrientation_Right: case eUBDockOrientation_Right:
if (parentWidget()) { if (parentWidget()) {
origin.setX(parentWidget()->width() - width() - border() * 2); origin.setX(parentWidget()->width() - width() - border() * 2);
} }
break; break;
case eUBDockOrientation_Top: ; case eUBDockOrientation_Top: ;
case eUBDockOrientation_Bottom: ; case eUBDockOrientation_Bottom: ;
} }
mTabPalette->move(origin.x(), origin.y()); mTabPalette->move(origin.x(), origin.y());
} }
void UBDockPalette::resizeTabs() void UBDockPalette::resizeTabs()
{ {
int numTabs = mTabWidgets.size(); int numTabs = mTabWidgets.size();
mTabPalette->setFixedSize(2 * border(), (numTabs * TABSIZE) + qMax(numTabs - 1, 0) * tabSpacing()); mTabPalette->setFixedSize(2 * border(), (numTabs * TABSIZE) + qMax(numTabs - 1, 0) * tabSpacing());
} }
QRect UBDockPalette::getTabPaletteRect() QRect UBDockPalette::getTabPaletteRect()
{ {
QRect tabsRect = mTabPalette->rect(); QRect tabsRect = mTabPalette->rect();
QPoint topLeft = mTabPalette->mapToParent(tabsRect.topLeft()); QPoint topLeft = mTabPalette->mapToParent(tabsRect.topLeft());
QPoint bottomRight = mTabPalette->mapToParent(tabsRect.bottomRight()); QPoint bottomRight = mTabPalette->mapToParent(tabsRect.bottomRight());
return QRect(topLeft, bottomRight); return QRect(topLeft, bottomRight);
} }
void UBDockPalette::assignParent(QWidget *widget) void UBDockPalette::assignParent(QWidget *widget)
{ {
setParent(widget); setParent(widget);
mTabPalette->setParent(widget); mTabPalette->setParent(widget);
} }
void UBDockPalette::setVisible(bool visible) void UBDockPalette::setVisible(bool visible)
{ {
QWidget::setVisible(visible); QWidget::setVisible(visible);
mTabPalette->setVisible(visible); mTabPalette->setVisible(visible);
} }
bool UBDockPalette::switchMode(eUBDockPaletteWidgetMode mode) bool UBDockPalette::switchMode(eUBDockPaletteWidgetMode mode)
{ {
bool hasVisibleElements = false; bool hasVisibleElements = false;
//-------------------------------// //-------------------------------//
// get full right palette widgets list, parse it, show all widgets for BOARD mode, and hide all other // get full right palette widgets list, parse it, show all widgets for BOARD mode, and hide all other
for(int i = 0; i < mRegisteredWidgets.size(); i++) for(int i = 0; i < mRegisteredWidgets.size(); i++)
{ {
UBDockPaletteWidget* pNextWidget = mRegisteredWidgets.at(i); UBDockPaletteWidget* pNextWidget = mRegisteredWidgets.at(i);
if( pNextWidget != NULL ) if( pNextWidget != NULL )
{ {
if( pNextWidget->visibleInMode(mode) ) if( pNextWidget->visibleInMode(mode) )
{ {
addTab(pNextWidget); addTab(pNextWidget);
hasVisibleElements = true; hasVisibleElements = true;
} }
else else
{ {
removeTab(pNextWidget); removeTab(pNextWidget);
} }
} }
} }
//-------------------------------// //-------------------------------//
if(mRegisteredWidgets.size() > 0) if(mRegisteredWidgets.size() > 0)
showTabWidget(0); showTabWidget(0);
update(); update();
return hasVisibleElements; return hasVisibleElements;
} }
UBTabDockPalette::UBTabDockPalette(UBDockPalette *dockPalette, QWidget *parent) : UBTabDockPalette::UBTabDockPalette(UBDockPalette *dockPalette, QWidget *parent) :
QWidget(parent) QWidget(parent)
, dock(dockPalette) , dock(dockPalette)
, mVerticalOffset(0) , mVerticalOffset(0)
, mFlotable(false) , mFlotable(false)
{ {
int numTabs = dock->mTabWidgets.size(); int numTabs = dock->mTabWidgets.size();
resize(2 * dock->border(), (numTabs * TABSIZE) + qMax(numTabs - 1, 0) * dock->tabSpacing()); resize(2 * dock->border(), (numTabs * TABSIZE) + qMax(numTabs - 1, 0) * dock->tabSpacing());
setAttribute(Qt::WA_TranslucentBackground); setAttribute(Qt::WA_TranslucentBackground);
} }
void UBTabDockPalette::paintEvent(QPaintEvent *) void UBTabDockPalette::paintEvent(QPaintEvent *)
{ {
int nTabs = dock->mTabWidgets.size(); int nTabs = dock->mTabWidgets.size();
if (nTabs <= 0) { if (nTabs <= 0) {
qDebug() << "not enough tabs"; qDebug() << "not enough tabs";
return; return;
} }
QPainter painter(this); QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing); painter.setRenderHint(QPainter::Antialiasing);
painter.setPen(Qt::NoPen); painter.setPen(Qt::NoPen);
painter.setBrush(dock->mBackgroundBrush); painter.setBrush(dock->mBackgroundBrush);
int yFrom = 0; int yFrom = 0;
for (int i = 0; i < nTabs; i++) { for (int i = 0; i < nTabs; i++) {
UBDockPaletteWidget* pCrntWidget = dock->mTabWidgets.at(i); UBDockPaletteWidget* pCrntWidget = dock->mTabWidgets.at(i);
QPainterPath path; QPainterPath path;
path.setFillRule(Qt::WindingFill); path.setFillRule(Qt::WindingFill);
QPixmap iconPixmap; QPixmap iconPixmap;
switch (dock->mOrientation) { switch (dock->mOrientation) {
case eUBDockOrientation_Left: case eUBDockOrientation_Left:
path.addRect(0, yFrom, width() / 2, TABSIZE); path.addRect(0, yFrom, width() / 2, TABSIZE);
path.addRoundedRect(0, yFrom, width(), TABSIZE, dock->radius(), dock->radius()); path.addRoundedRect(0, yFrom, width(), TABSIZE, dock->radius(), dock->radius());
if (pCrntWidget) { if (pCrntWidget) {
if(dock->mCollapseWidth >= dock->width()) { if(dock->mCollapseWidth >= dock->width()) {
// Get the collapsed icon // Get the collapsed icon
iconPixmap = pCrntWidget->iconToRight(); iconPixmap = pCrntWidget->iconToRight();
} else { } else {
// Get the expanded icon // Get the expanded icon
iconPixmap = pCrntWidget->iconToLeft(); iconPixmap = pCrntWidget->iconToLeft();
} }
} }
break; break;
case eUBDockOrientation_Right: case eUBDockOrientation_Right:
path.addRect(width() /2, yFrom, width() / 2, TABSIZE); path.addRect(width() /2, yFrom, width() / 2, TABSIZE);
path.addRoundedRect(0, yFrom, width(), TABSIZE, dock->radius(), dock->radius()); path.addRoundedRect(0, yFrom, width(), TABSIZE, dock->radius(), dock->radius());
if (pCrntWidget) { if (pCrntWidget) {
if(dock->mCollapseWidth >= dock->width()) { if(dock->mCollapseWidth >= dock->width()) {
// Get the collapsed icon // Get the collapsed icon
iconPixmap = pCrntWidget->iconToLeft(); iconPixmap = pCrntWidget->iconToLeft();
} else { } else {
// Get the expanded icon // Get the expanded icon
iconPixmap = pCrntWidget->iconToRight(); iconPixmap = pCrntWidget->iconToRight();
} }
} }
break; break;
case eUBDockOrientation_Top: ; case eUBDockOrientation_Top: ;
case eUBDockOrientation_Bottom: ; case eUBDockOrientation_Bottom: ;
default: default:
break; break;
} }
painter.save(); painter.save();
QPixmap transparencyPix(":/images/tab_mask.png"); QPixmap transparencyPix(":/images/tab_mask.png");
if (dock->mCurrentTab != i) { if (dock->mCurrentTab != i) {
iconPixmap.setAlphaChannel(transparencyPix); iconPixmap.setAlphaChannel(transparencyPix);
QColor color(0x7F, 0x7F, 0x7F, 0x3F); QColor color(0x7F, 0x7F, 0x7F, 0x3F);
painter.setBrush(QBrush(color)); painter.setBrush(QBrush(color));
} }
painter.drawPath(path); painter.drawPath(path);
painter.drawPixmap(2, yFrom + 2, width() - 4, TABSIZE - 4, iconPixmap); painter.drawPixmap(2, yFrom + 2, width() - 4, TABSIZE - 4, iconPixmap);
yFrom += (TABSIZE + dock->tabSpacing()); yFrom += (TABSIZE + dock->tabSpacing());
painter.restore(); painter.restore();
} }
} }
UBTabDockPalette::~UBTabDockPalette() UBTabDockPalette::~UBTabDockPalette()
{ {
...@@ -661,97 +649,97 @@ UBTabDockPalette::~UBTabDockPalette() ...@@ -661,97 +649,97 @@ UBTabDockPalette::~UBTabDockPalette()
void UBTabDockPalette::mousePressEvent(QMouseEvent *event) void UBTabDockPalette::mousePressEvent(QMouseEvent *event)
{ {
dock->mClickTime = QTime::currentTime(); dock->mClickTime = QTime::currentTime();
// The goal here is to verify if the user can resize the widget. // The goal here is to verify if the user can resize the widget.
// It is only possible to resize it if the border is selected // It is only possible to resize it if the border is selected
QPoint p = event->pos(); QPoint p = event->pos();
dock->mMousePressPos = p; dock->mMousePressPos = p;
dock->mResized = false; dock->mResized = false;
switch(dock->mOrientation) { switch(dock->mOrientation) {
case eUBDockOrientation_Left: case eUBDockOrientation_Left:
dock->mCanResize = true; dock->mCanResize = true;
break; break;
case eUBDockOrientation_Right: case eUBDockOrientation_Right:
dock->mCanResize = true; dock->mCanResize = true;
break; break;
case eUBDockOrientation_Top: case eUBDockOrientation_Top:
// Not supported yet // Not supported yet
break; break;
case eUBDockOrientation_Bottom: case eUBDockOrientation_Bottom:
// Not supported yet // Not supported yet
break; break;
default: default:
break; break;
} }
} }
void UBTabDockPalette::mouseMoveEvent(QMouseEvent *event) void UBTabDockPalette::mouseMoveEvent(QMouseEvent *event)
{ {
QPoint p = event->pos(); QPoint p = event->pos();
if(dock->mCanResize && ((dock->mMousePressPos - p).manhattanLength() > QApplication::startDragDistance())) if(dock->mCanResize && ((dock->mMousePressPos - p).manhattanLength() > QApplication::startDragDistance()))
{ {
if (qAbs(dock->mMousePressPos.y() - p.y()) > 10 && mFlotable) { if (qAbs(dock->mMousePressPos.y() - p.y()) > 10 && mFlotable) {
qDebug() << "y differences" << dock->mMousePressPos.y() << p.y(); qDebug() << "y differences" << dock->mMousePressPos.y() << p.y();
mVerticalOffset += p.y() - dock->mMousePressPos.y(); mVerticalOffset += p.y() - dock->mMousePressPos.y();
move(this->pos().x(), p.y()); move(this->pos().x(), p.y());
} }
switch(dock->mOrientation) { switch(dock->mOrientation) {
case eUBDockOrientation_Left: case eUBDockOrientation_Left:
p.setX(p.x() + dock->width()); p.setX(p.x() + dock->width());
if(p.x() < dock->collapseWidth() && p.x() >= dock->minimumWidth()) { if(p.x() < dock->collapseWidth() && p.x() >= dock->minimumWidth()) {
dock->resize(0, dock->height()); dock->resize(0, dock->height());
dock->mLastWidth = dock->collapseWidth() + 1; //dock->mLastWidth = dock->collapseWidth() + 1;
dock->mResized = true; dock->mResized = true;
} else if (p.x() <= dock->maximumWidth() && p.x() >= dock->minimumWidth()) { } else if (p.x() <= dock->maximumWidth() && p.x() >= dock->minimumWidth()) {
dock->resize(p.x(), dock->height()); dock->resize(p.x(), dock->height());
dock->mResized = true; dock->mResized = true;
} }
break; break;
case eUBDockOrientation_Right: case eUBDockOrientation_Right:
p.setX(p.x() - 2 * dock->border()); p.setX(p.x() - 2 * dock->border());
if((dock->x() + p.x() > dock->parentWidget()->width() - dock->collapseWidth()) && (dock->x() + p.x() < dock->parentWidget()->width())) { if((dock->x() + p.x() > dock->parentWidget()->width() - dock->collapseWidth()) && (dock->x() + p.x() < dock->parentWidget()->width())) {
dock->resize(0, dock->height()); dock->resize(0, dock->height());
dock->mLastWidth = dock->collapseWidth() + 1; //dock->mLastWidth = dock->collapseWidth() + 1;
dock->mResized = true; dock->mResized = true;
} else if((dock->x() + p.x() >= dock->parentWidget()->width() - dock->maximumWidth()) && (dock->x() + p.x() <= dock->parentWidget()->width() - dock->minimumWidth())) { } else if((dock->x() + p.x() >= dock->parentWidget()->width() - dock->maximumWidth()) && (dock->x() + p.x() <= dock->parentWidget()->width() - dock->minimumWidth())) {
dock->resize(dock->parentWidget()->width() - (dock->x() + p.x()), dock->height()); dock->resize(dock->parentWidget()->width() - (dock->x() + p.x()), dock->height());
dock->mResized = true; dock->mResized = true;
} }
break; break;
case eUBDockOrientation_Top: case eUBDockOrientation_Top:
case eUBDockOrientation_Bottom: case eUBDockOrientation_Bottom:
if(p.y() <= dock->maximumHeight()) { if(p.y() <= dock->maximumHeight()) {
dock->resize(width(), p.y()); dock->resize(width(), p.y());
dock->mResized = true; dock->mResized = true;
} }
break; break;
default: default:
break; break;
} }
} }
} }
void UBTabDockPalette::mouseReleaseEvent(QMouseEvent *event) void UBTabDockPalette::mouseReleaseEvent(QMouseEvent *event)
{ {
Q_UNUSED(event); Q_UNUSED(event);
if(!dock->mResized && dock->mClickTime.elapsed() < CLICKTIME) { if(!dock->mResized && dock->mClickTime.elapsed() < CLICKTIME) {
int nbTabs = dock->mTabWidgets.size(); int nbTabs = dock->mTabWidgets.size();
int clickedTab = 0; int clickedTab = 0;
// If the clicked position is in the tab, perform the related action // If the clicked position is in the tab, perform the related action
if(dock->mMousePressPos.x() >= 0 && if(dock->mMousePressPos.x() >= 0 &&
dock->mMousePressPos.x() <= width() && dock->mMousePressPos.x() <= width() &&
dock->mMousePressPos.y() >= 0 && dock->mMousePressPos.y() >= 0 &&
dock->mMousePressPos.y() <= nbTabs * TABSIZE + (nbTabs -1)*dock->tabSpacing()) { dock->mMousePressPos.y() <= nbTabs * TABSIZE + (nbTabs -1)*dock->tabSpacing()) {
clickedTab = (dock->mMousePressPos.y()) / (TABSIZE + dock->tabSpacing()); clickedTab = (dock->mMousePressPos.y()) / (TABSIZE + dock->tabSpacing());
dock->tabClicked(clickedTab); dock->tabClicked(clickedTab);
} }
} }
dock->mCanResize = false; dock->mCanResize = false;
} }
...@@ -29,7 +29,10 @@ UBLeftPalette::UBLeftPalette(QWidget *parent, const char *name): ...@@ -29,7 +29,10 @@ UBLeftPalette::UBLeftPalette(QWidget *parent, const char *name):
mLastWidth = UBSettings::settings()->leftLibPaletteWidth->get().toInt(); mLastWidth = UBSettings::settings()->leftLibPaletteWidth->get().toInt();
mCollapseWidth = 150; mCollapseWidth = 150;
resize(mLastWidth, parentWidget()->height()); if(UBSettings::settings()->leftLibPaletteIsCollapsed->get().toBool())
resize(0,parentWidget()->height());
else
resize(mLastWidth, parentWidget()->height());
} }
/** /**
...@@ -54,6 +57,9 @@ void UBLeftPalette::updateMaxWidth() ...@@ -54,6 +57,9 @@ void UBLeftPalette::updateMaxWidth()
*/ */
void UBLeftPalette::resizeEvent(QResizeEvent *event) void UBLeftPalette::resizeEvent(QResizeEvent *event)
{ {
UBSettings::settings()->leftLibPaletteWidth->set(width()); int newWidth = width();
if(newWidth > mCollapseWidth)
UBSettings::settings()->leftLibPaletteWidth->set(newWidth);
UBSettings::settings()->leftLibPaletteIsCollapsed->set(newWidth == 0);
UBDockPalette::resizeEvent(event); UBDockPalette::resizeEvent(event);
} }
...@@ -33,8 +33,6 @@ UBNavigatorPalette::UBNavigatorPalette(QWidget *parent, const char *name): ...@@ -33,8 +33,6 @@ UBNavigatorPalette::UBNavigatorPalette(QWidget *parent, const char *name):
{ {
setOrientation(eUBDockOrientation_Left); setOrientation(eUBDockOrientation_Left);
setMaximumWidth(300); setMaximumWidth(300);
//mCollapsedIcon = QPixmap(":images/pages_open.png");
//mIcon = QPixmap(":images/pages_close.png");
resize(UBSettings::settings()->navigPaletteWidth->get().toInt(), height()); resize(UBSettings::settings()->navigPaletteWidth->get().toInt(), height());
mLastWidth = 300; mLastWidth = 300;
......
...@@ -27,11 +27,13 @@ UBRightPalette::UBRightPalette(QWidget *parent, const char *name): ...@@ -27,11 +27,13 @@ UBRightPalette::UBRightPalette(QWidget *parent, const char *name):
{ {
setObjectName(name); setObjectName(name);
setOrientation(eUBDockOrientation_Right); setOrientation(eUBDockOrientation_Right);
mLastWidth = UBSettings::settings()->rightLibPaletteWidth->get().toInt();
mCollapseWidth = 150; mCollapseWidth = 150;
resize(mLastWidth, parentWidget()->height()); mLastWidth = UBSettings::settings()->rightLibPaletteWidth->get().toInt();
if(UBSettings::settings()->rightLibPaletteIsCollapsed->get().toBool())
resize(0,parentWidget()->height());
else
resize(mLastWidth, parentWidget()->height());
} }
/** /**
...@@ -59,8 +61,11 @@ void UBRightPalette::mouseMoveEvent(QMouseEvent *event) ...@@ -59,8 +61,11 @@ void UBRightPalette::mouseMoveEvent(QMouseEvent *event)
*/ */
void UBRightPalette::resizeEvent(QResizeEvent *event) void UBRightPalette::resizeEvent(QResizeEvent *event)
{ {
int newWidth = width();
if(newWidth > mCollapseWidth)
UBSettings::settings()->rightLibPaletteWidth->set(newWidth);
UBSettings::settings()->rightLibPaletteIsCollapsed->set(newWidth == 0);
UBDockPalette::resizeEvent(event); UBDockPalette::resizeEvent(event);
UBSettings::settings()->rightLibPaletteWidth->set(width());
emit resized(); emit resized();
} }
......
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