GUI: Fix MHTabBar not painting the tab bar correctly
( Fixes https://github.com/Nukem9/IDASkins/issues/1 )
This commit is contained in:
parent
ab2727600d
commit
1515cb2d2d
|
@ -29,16 +29,6 @@ MHTabWidget::~MHTabWidget(void)
|
|||
delete m_tabBar;
|
||||
}
|
||||
|
||||
QTabBar* MHTabWidget::tabBar()
|
||||
{
|
||||
return m_tabBar;
|
||||
}
|
||||
|
||||
int MHTabWidget::count() const
|
||||
{
|
||||
return QTabWidget::count() + m_Windows.size();
|
||||
}
|
||||
|
||||
QWidget* MHTabWidget::widget(int index) const
|
||||
{
|
||||
int baseCount = QTabWidget::count();
|
||||
|
@ -51,38 +41,39 @@ QWidget* MHTabWidget::widget(int index) const
|
|||
return m_Windows.at(index - baseCount);
|
||||
}
|
||||
|
||||
void MHTabWidget::setCurrentIndex(int index)
|
||||
int MHTabWidget::count() const
|
||||
{
|
||||
// Check if it's just a normal tab
|
||||
if(index < QTabWidget::count())
|
||||
return QTabWidget::count() + m_Windows.size();
|
||||
}
|
||||
|
||||
// Convert an external window to a widget tab
|
||||
void MHTabWidget::AttachTab(QWidget* parent)
|
||||
{
|
||||
// Retrieve widget
|
||||
MHDetachedWindow* detachedWidget = reinterpret_cast<MHDetachedWindow*>(parent);
|
||||
QWidget* tearOffWidget = detachedWidget->centralWidget();
|
||||
|
||||
// Reattach the tab
|
||||
int newIndex = addTab(tearOffWidget, detachedWidget->windowIcon(), detachedWidget->windowTitle());
|
||||
|
||||
// Remove it from the windows list
|
||||
for(int i = 0; i < m_Windows.size(); i++)
|
||||
{
|
||||
QTabWidget::setCurrentIndex(index);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Otherwise it's going to be a window (just bring it up)
|
||||
MHDetachedWindow* window = dynamic_cast<MHDetachedWindow*>(widget(index)->parent());
|
||||
window->activateWindow();
|
||||
window->showNormal();
|
||||
window->setFocus();
|
||||
if(m_Windows.at(i) == tearOffWidget)
|
||||
m_Windows.removeAt(i);
|
||||
}
|
||||
|
||||
// Make Active
|
||||
if(newIndex != -1)
|
||||
setCurrentIndex(newIndex);
|
||||
|
||||
// Cleanup Window
|
||||
disconnect(detachedWidget, SIGNAL(OnClose(QWidget*)), this, SLOT(AttachTab(QWidget*)));
|
||||
detachedWidget->hide();
|
||||
detachedWidget->close();
|
||||
}
|
||||
|
||||
void MHTabWidget::setCurrentWidget(QWidget* widget)
|
||||
{
|
||||
Q_UNUSED(widget);
|
||||
// To be implemented.
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
void MHTabWidget::MoveTab(int fromIndex, int toIndex)
|
||||
{
|
||||
removeTab(fromIndex);
|
||||
insertTab(toIndex, widget(fromIndex), tabIcon(fromIndex), tabText(fromIndex));
|
||||
setCurrentIndex(toIndex);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// Convert a tab to an external window
|
||||
void MHTabWidget::DetachTab(int index, QPoint & dropPoint)
|
||||
{
|
||||
Q_UNUSED(dropPoint);
|
||||
|
@ -122,36 +113,50 @@ void MHTabWidget::DetachTab(int index, QPoint & dropPoint)
|
|||
detachedWidget->showNormal();
|
||||
}
|
||||
|
||||
// Swap two tab indices
|
||||
void MHTabWidget::MoveTab(int fromIndex, int toIndex)
|
||||
{
|
||||
removeTab(fromIndex);
|
||||
insertTab(toIndex, widget(fromIndex), tabIcon(fromIndex), tabText(fromIndex));
|
||||
setCurrentIndex(toIndex);
|
||||
}
|
||||
|
||||
// Remove a tab, while still keeping the widget intact
|
||||
void MHTabWidget::DeleteTab(int index)
|
||||
{
|
||||
removeTab(index);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
void MHTabWidget::AttachTab(QWidget* parent)
|
||||
void MHTabWidget::setCurrentIndex(int index)
|
||||
{
|
||||
// Retrieve widget
|
||||
MHDetachedWindow* detachedWidget = reinterpret_cast<MHDetachedWindow*>(parent);
|
||||
QWidget* tearOffWidget = detachedWidget->centralWidget();
|
||||
|
||||
// Reattach the tab
|
||||
int newIndex = addTab(tearOffWidget, detachedWidget->windowIcon(), detachedWidget->windowTitle());
|
||||
|
||||
// Remove it from the windows list
|
||||
for(int i = 0; i < m_Windows.size(); i++)
|
||||
// Check if it's just a normal tab
|
||||
if(index < QTabWidget::count())
|
||||
{
|
||||
if(m_Windows.at(i) == tearOffWidget)
|
||||
m_Windows.removeAt(i);
|
||||
QTabWidget::setCurrentIndex(index);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Otherwise it's going to be a window (just bring it up)
|
||||
MHDetachedWindow* window = dynamic_cast<MHDetachedWindow*>(widget(index)->parent());
|
||||
window->activateWindow();
|
||||
window->showNormal();
|
||||
window->setFocus();
|
||||
}
|
||||
}
|
||||
|
||||
// Make Active
|
||||
if(newIndex != -1)
|
||||
setCurrentIndex(newIndex);
|
||||
void MHTabWidget::paintEvent(QPaintEvent *event)
|
||||
{
|
||||
QTabWidget::paintEvent(event);
|
||||
|
||||
// Cleanup Window
|
||||
disconnect(detachedWidget, SIGNAL(OnClose(QWidget*)), this, SLOT(AttachTab(QWidget*)));
|
||||
detachedWidget->hide();
|
||||
detachedWidget->close();
|
||||
// Force the tab bar to draw AFTER the main elements
|
||||
// do. This prevents the bar from being hidden
|
||||
// when using custom CSS.
|
||||
tabBar()->update();
|
||||
}
|
||||
|
||||
QTabBar* MHTabWidget::tabBar() const
|
||||
{
|
||||
return m_tabBar;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
|
@ -165,7 +170,9 @@ MHDetachedWindow::~MHDetachedWindow(void)
|
|||
{
|
||||
}
|
||||
|
||||
void MHDetachedWindow::closeEvent(QCloseEvent* /*event*/)
|
||||
void MHDetachedWindow::closeEvent(QCloseEvent* event)
|
||||
{
|
||||
Q_UNUSED(event);
|
||||
|
||||
emit OnClose(this);
|
||||
}
|
||||
|
|
|
@ -24,29 +24,23 @@ class MHTabWidget: public QTabWidget
|
|||
public:
|
||||
MHTabWidget(QWidget* parent, bool allowDetach = true, bool allowDelete = false);
|
||||
virtual ~MHTabWidget(void);
|
||||
QTabBar* tabBar();
|
||||
|
||||
QWidget* widget(int index) const;
|
||||
int count() const;
|
||||
|
||||
public slots:
|
||||
int count() const;
|
||||
QWidget* widget(int index) const;
|
||||
|
||||
// Move Tab
|
||||
void MoveTab(int fromIndex, int toIndex);
|
||||
|
||||
// Detach Tab
|
||||
void DetachTab(int index, QPoint &);
|
||||
|
||||
// Attach Tab
|
||||
void AttachTab(QWidget* parent);
|
||||
|
||||
// Delete Tab
|
||||
void DetachTab(int index, QPoint &);
|
||||
void MoveTab(int fromIndex, int toIndex);
|
||||
void DeleteTab(int index);
|
||||
|
||||
public Q_SLOTS:
|
||||
void setCurrentIndex(int index);
|
||||
void setCurrentWidget(QWidget* widget);
|
||||
|
||||
protected:
|
||||
QTabBar* tabBar() const;
|
||||
|
||||
void paintEvent(QPaintEvent *event);
|
||||
|
||||
private:
|
||||
MHTabBar* m_tabBar;
|
||||
|
@ -64,6 +58,7 @@ private:
|
|||
class MHDetachedWindow : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
MHDetachedWindow(QWidget* parent = 0, MHTabWidget* tabwidget = 0);
|
||||
~MHDetachedWindow(void);
|
||||
|
|
Loading…
Reference in New Issue