Add custom properties to ToolWindowManager toolwindows, update titles

* Two properties added - DisallowUserDocking which completely prevents
  a toolwindow from being dragged or docked other than programmatically.
* HideCloseButton also hides the close button that normally appears on
  the tabs created
* Also tabs now watch for title change signals and update the titles in
  tabs.
This commit is contained in:
baldurk
2015-07-10 15:24:24 +02:00
parent 227e6feddd
commit 4627ead8f2
4 changed files with 71 additions and 0 deletions
@@ -80,6 +80,17 @@ ToolWindowManager::~ToolWindowManager() {
}
}
void ToolWindowManager::setToolWindowProperties(QWidget* toolWindow, ToolWindowManager::ToolWindowProperty properties) {
m_toolWindowProperties[toolWindow] = properties;
ToolWindowManagerArea *area = areaOf(toolWindow);
if(area)
area->updateToolWindow(toolWindow);
}
ToolWindowManager::ToolWindowProperty ToolWindowManager::toolWindowProperties(QWidget* toolWindow) {
return m_toolWindowProperties[toolWindow];
}
void ToolWindowManager::addToolWindow(QWidget *toolWindow, const AreaReference &area) {
addToolWindows(QList<QWidget*>() << toolWindow, area);
}
@@ -97,6 +108,8 @@ void ToolWindowManager::addToolWindows(QList<QWidget *> toolWindows, const ToolW
toolWindow->hide();
toolWindow->setParent(0);
m_toolWindows << toolWindow;
m_toolWindowProperties[toolWindow] = ToolWindowProperty(0);
QObject::connect(toolWindow, &QWidget::windowTitleChanged, this, &ToolWindowManager::windowTitleChanged);
}
moveToolWindows(toolWindows, area);
}
@@ -211,6 +224,7 @@ void ToolWindowManager::removeToolWindow(QWidget *toolWindow) {
}
moveToolWindow(toolWindow, NoArea);
m_toolWindows.removeOne(toolWindow);
m_toolWindowProperties.remove(toolWindow);
}
void ToolWindowManager::setSuggestionSwitchInterval(int msec) {
@@ -373,6 +387,9 @@ void ToolWindowManager::startDrag(const QList<QWidget *> &toolWindows) {
qWarning("ToolWindowManager::execDrag: drag is already in progress");
return;
}
foreach(QWidget* toolWindow, toolWindows) {
if(toolWindowProperties(toolWindow) & DisallowUserDocking) { return; }
}
if (toolWindows.isEmpty()) { return; }
m_draggedToolWindows = toolWindows;
m_dragIndicator->setPixmap(generateDragPixmap(toolWindows));
@@ -675,6 +692,17 @@ void ToolWindowManager::tabCloseRequested(int index) {
hideToolWindow(toolWindow);
}
void ToolWindowManager::windowTitleChanged(const QString &title) {
QWidget* toolWindow = qobject_cast<QWidget*>(sender());
if(!toolWindow) {
return;
}
ToolWindowManagerArea *area = areaOf(toolWindow);
if(area) {
area->updateToolWindow(toolWindow);
}
}
QSplitter *ToolWindowManager::createSplitter() {
QSplitter* splitter = new QSplitter();
splitter->setChildrenCollapsible(false);
@@ -103,6 +103,14 @@ public:
*/
virtual ~ToolWindowManager();
//! Toolwindow properties
enum ToolWindowProperty {
//! Disables all drag/docking ability by the user
DisallowUserDocking = 0x1,
//! Hides the close button on the tab for this tool window
HideCloseButton = 0x2,
};
//! Type of AreaReference.
enum AreaReferenceType {
//! The area tool windows has been added to most recently.
@@ -157,6 +165,16 @@ public:
*/
void addToolWindow(QWidget* toolWindow, const AreaReference& area);
/*!
* Sets the set of \a properties on \a toolWindow that is already added to the manager.
*/
void setToolWindowProperties(QWidget* toolWindow, ToolWindowProperty properties);
/*!
* Returns the set of \a properties on \a toolWindow.
*/
ToolWindowProperty toolWindowProperties(QWidget* toolWindow);
/*!
* \brief Adds \a toolWindows to the manager and moves it to the position specified by
* \a area.
@@ -250,6 +268,7 @@ signals:
private:
QList<QWidget*> m_toolWindows; // all added tool windows
QHash<QWidget*, ToolWindowProperty> m_toolWindowProperties; // all tool window properties
QList<ToolWindowManagerArea*> m_areas; // all areas for this manager
QList<ToolWindowManagerWrapper*> m_wrappers; // all wrappers for this manager
int m_borderSensitivity;
@@ -309,7 +328,11 @@ protected:
private slots:
void showNextDropSuggestion();
void tabCloseRequested(int index);
void windowTitleChanged(const QString &title);
};
inline ToolWindowManager::ToolWindowProperty operator|(ToolWindowManager::ToolWindowProperty a, ToolWindowManager::ToolWindowProperty b)
{ return ToolWindowManager::ToolWindowProperty(int(a) | int(b)); }
#endif // TOOLWINDOWMANAGER_H
@@ -53,6 +53,9 @@ void ToolWindowManagerArea::addToolWindows(const QList<QWidget *> &toolWindows)
int index = 0;
foreach(QWidget* toolWindow, toolWindows) {
index = addTab(toolWindow, toolWindow->windowIcon(), toolWindow->windowTitle());
if(m_manager->toolWindowProperties(toolWindow) & ToolWindowManager::HideCloseButton) {
tabBar()->tabButton(index, QTabBar::RightSide)->resize(0, 0);
}
}
setCurrentIndex(index);
m_manager->m_lastUsedArea = this;
@@ -66,6 +69,18 @@ QList<QWidget *> ToolWindowManagerArea::toolWindows() {
return result;
}
void ToolWindowManagerArea::updateToolWindow(QWidget* toolWindow) {
int index = indexOf(toolWindow);
if(index >= 0) {
if(m_manager->toolWindowProperties(toolWindow) & ToolWindowManager::HideCloseButton) {
tabBar()->tabButton(index, QTabBar::RightSide)->resize(0, 0);
} else {
tabBar()->tabButton(index, QTabBar::RightSide)->resize(16, 16);
}
tabBar()->setTabText(index, toolWindow->windowTitle());
}
}
void ToolWindowManagerArea::mousePressEvent(QMouseEvent *) {
if (qApp->mouseButtons() == Qt::LeftButton) {
m_dragCanStart = true;
@@ -57,6 +57,11 @@ public:
*/
QList<QWidget*> toolWindows();
/*!
* Updates the \a toolWindow to its current properties and title.
*/
void updateToolWindow(QWidget* toolWindow);
protected:
//! Reimplemented from QTabWidget::mousePressEvent.
virtual void mousePressEvent(QMouseEvent *);