Files
pgadmin4/runtime/TabWindow.cpp
T
Neel Patel 8f146ebb4c Support tabs in the runtime browser.
Added functionality to open different website link and load the
website data to different tab. To achieve this, new customized
QTabWidget and QWebView are added to render the data to WebView
widget. All the widgets (New Tab, WebViewWinodw, and QToolButton)
are added dynamically. QToolButton is used to traverse back and
forward to web document opened in WebViewWindow.

Introduced the New class called WebViewWindow which is derived
from QWebView. Each tab of the QTabWidget contains the instance
of WebViewWindow class. WebViewWindow class is useful to display
the web document.

Introduced New class called TabWindow which is derived from
QTabWidget. This class is useful to achieve following functionality:
  - Customize the close button of tabbar so that it can only be
    visible other then main pgAdmin 4 window.
  - Enable/Disable the toolbutton added left side of tabbar
    depending on the web history traversed by the user in WebViewWindow.
  - Set the tooltip text of the tabbar depending on the title change
    event of WebViewWindow class.

Modified the Qt project file to support the both the version
of python 2 and python 3.

Qt5 is recommended to test pgAdmin4 in dektop mode.
2016-01-18 14:33:28 +00:00

135 lines
4.0 KiB
C++

//////////////////////////////////////////////////////////////////////////
//
// pgAdmin 4 - PostgreSQL Tools
//
// Copyright (C) 2013 - 2016, The pgAdmin Development Team
// This software is released under the PostgreSQL Licence
//
// TabWindow.cpp - Implementation of the custom tab widget
//
//////////////////////////////////////////////////////////////////////////
#include "pgAdmin4.h"
// App headers
#include "TabWindow.h"
TabWindow::TabWindow(QWidget *parent) :
QTabWidget(parent)
{
setParent(parent);
setTabsClosable(false);
setElideMode(Qt::ElideRight);
#ifdef __APPLE__
m_testTabBar = new TabBar();
setTabBar(m_testTabBar);
#endif
}
// Hide the close button of given index displayed on right side of tab
void TabWindow::enableDisableToolButton(const int &index)
{
QToolButton *toolBtnPtr = NULL;
WebViewWindow *webviewPtr = NULL;
// Enable/disable the toolbutton based on the history
QWidget *tab1 = this->widget(index);
if (tab1 != NULL)
{
QList<QWidget*> widgetList = tab1->findChildren<QWidget*>();
foreach( QWidget* widgetPtr, widgetList )
{
if (widgetPtr != NULL)
webviewPtr = dynamic_cast<WebViewWindow*>(widgetPtr);
}
}
QWidget *tab = tabBar()->tabButton(index, QTabBar::LeftSide);
if (tab != NULL)
{
QList<QWidget*> widgetList = tab->findChildren<QWidget*>();
foreach( QWidget* widgetPtr, widgetList )
{
if (widgetPtr != NULL)
{
toolBtnPtr = dynamic_cast<QToolButton*>(widgetPtr);
if (webviewPtr != NULL && toolBtnPtr != NULL)
{
if (!QString::compare(toolBtnPtr->text(), PGA_BTN_BACK, Qt::CaseInsensitive))
{
if (webviewPtr->page()->history()->canGoBack())
toolBtnPtr->setDisabled(false);
else
toolBtnPtr->setDisabled(true);
}
if (!QString::compare(toolBtnPtr->text(), PGA_BTN_FORWARD, Qt::CaseInsensitive))
{
if (webviewPtr->page()->history()->canGoForward())
toolBtnPtr->setDisabled(false);
else
toolBtnPtr->setDisabled(true);
}
}
}
}
}
}
// Get the index of the pushbutton which is requested by user to close the tab
int TabWindow::getButtonIndex(QPushButton *btn)
{
QPushButton *nextBtnPtr = NULL;
int loopCount = 0;
int totalTabs = this->count();
for (loopCount = 1;loopCount < totalTabs;loopCount++)
{
QWidget *tab = tabBar()->tabButton(loopCount, QTabBar::RightSide);
if (tab != NULL)
{
nextBtnPtr = dynamic_cast<QPushButton*>(tab);
if (nextBtnPtr != NULL && btn != NULL && nextBtnPtr == btn)
return loopCount;
}
}
return 0;
}
// Show and Hide the toolbutton once the tab is deselected depending on the option
// option 0: Hide the toolButton
// option 1: Show the toolButton
void TabWindow::showHideToolButton(const int &index, const int &option)
{
QToolButton *toolBtnPtr = NULL;
QWidget *tab = tabBar()->tabButton(index, QTabBar::LeftSide);
if (tab != NULL)
{
QList<QWidget*> widgetList = tab->findChildren<QWidget*>();
foreach( QWidget* widgetPtr, widgetList )
{
if (widgetPtr != NULL)
{
toolBtnPtr = dynamic_cast<QToolButton*>(widgetPtr);
if (toolBtnPtr != NULL)
{
if (!option)
toolBtnPtr->hide();
else
toolBtnPtr->show();
}
}
}
}
}
// Set the tab tool tip text
void TabWindow::setTabToolTipText(const int &index, const QString &toolTipString)
{
tabBar()->setTabToolTip(index, toolTipString);
}