Commit 37f1032d authored by LEFEBVREJP email's avatar LEFEBVREJP email
Browse files

Adding radixwidgets with tabwidget that allows for add/removal of tabs.

parent ea3e95eb
Pipeline #5595 skipped
...@@ -3,4 +3,5 @@ TRIBITS_PACKAGE_DEFINE_DEPENDENCIES( ...@@ -3,4 +3,5 @@ TRIBITS_PACKAGE_DEFINE_DEPENDENCIES(
bug radixbug SS OPTIONAL bug radixbug SS OPTIONAL
io radixio SS OPTIONAL io radixio SS OPTIONAL
plot radixplot SS OPTIONAL plot radixplot SS OPTIONAL
widgets radixwidgets SS OPTIONAL
) )
##---------------------------------------------------------------------------##
## radixwidgets/CMakeLists.txt
## Jordan P. Lefebvre
## Wednesday June 8 9:11:40 2016
##---------------------------------------------------------------------------##
## CMAKE for radixwidgets
##---------------------------------------------------------------------------##
TRIBITS_SUBPACKAGE(widgets)
##---------------------------------------------------------------------------##
## PACKAGE CONFIGURE FILE
##---------------------------------------------------------------------------##
##---------------------------------------------------------------------------##
## HEADER AND SOURCE FILES
##---------------------------------------------------------------------------##
# C/C++ headers
SET(HEADERS
tabwidget.hh
)
#
# Moc the header files
#
IF(USE_QT4)
QT4_WRAP_CPP(MOC_FILES
${HEADERS}
)
#
# Process qt resource files
#QT4_ADD_RESOURCES(RESOURCE_RESULT
# ${RESOURCE_FILES}
#)
ELSE()
QT5_WRAP_CPP(MOC_FILES
${HEADERS}
)
#
# Process qt resource files
#QT5_ADD_RESOURCES(RESOURCE_RESULT
# ${RESOURCE_FILES}
#)
ENDIF()
# C/C++ source
SET(SOURCES
tabwidget.cc
)
##---------------------------------------------------------------------------##
## PACKAGE TARGETS AND INSTALL
##---------------------------------------------------------------------------##
TRIBITS_ADD_LIBRARY(
radixwidgets
SOURCES ${SOURCES} ${MOC_FILES} ${RESOURCE_RESULT}
)
INSTALL(FILES ${HEADERS}
DESTINATION include/radixwidgets)
#
# Add test directory for this package
#
#TRIBITS_ADD_TEST_DIRECTORIES(tests)
#
# Add example directory for this package
#
TRIBITS_ADD_EXAMPLE_DIRECTORIES(examples)
TRIBITS_SUBPACKAGE_POSTPROCESS()
##---------------------------------------------------------------------------##
## end of radixwidgets/CMakeLists.txt
##---------------------------------------------------------------------------##
##---------------------------------------------------------------------------##
## radixwidgets/cmake/Dependencies.cmake
## Jordan P. Lefebvre
## Tuesday May 31 12:57:18 2016
##---------------------------------------------------------------------------##
IF(NOT USE_QT5)
SET(USE_QT4 ON)
ENDIF()
IF(USE_QT4)
SET(QT_PACKAGES QT)
ELSE()
SET(QT_PACKAGES Qt5Gui)
ENDIF()
TRIBITS_PACKAGE_DEFINE_DEPENDENCIES(
LIB_REQUIRED_TPLS ${QT_PACKAGES}
)
##---------------------------------------------------------------------------##
## end of radixwidgets/cmake/Dependencies.cmake
##---------------------------------------------------------------------------##
# Provide access to QT-generated code
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR})
IF(USE_QT4)
QT4_WRAP_CPP(QMOC_FILES
radixtabwidget.hh
)
ELSE()
QT5_WRAP_CPP(QMOC_FILES
radixtabwidget.hh
)
ENDIF()
TRIBITS_ADD_EXECUTABLE(radixtabwidget
NOEXEPREFIX
SOURCES radixtabwidget.cc ${QMOC_FILES}
)
/*
* @file: mainwindow.cpp
* @author: Jordan P. Lefebvre, lefebvrejp@ornl.gov
*
* Created on May 31, 2016, 10:52 PM
*/
#include "radixtabwidget.hh"
#include <limits>
#include <QApplication>
#include <QLabel>
#include <QGridLayout>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent)
{
setGeometry(400, 250, 542, 390);
mTabWidget = new radix::TabWidget(this);
setCentralWidget(mTabWidget);
connect(mTabWidget
, SIGNAL(addTabRequested())
, this
, SLOT(addTabRequested()));
connect(mTabWidget
, SIGNAL(tabCloseRequested(int))
, this
, SLOT(tabCloseRequested(int)));
}
MainWindow::~MainWindow()
{
}
void MainWindow::addTabRequested()
{
static int tabId = 0;
tabId++;
QWidget* newTab = new QWidget(mTabWidget);
QGridLayout * layout = new QGridLayout(newTab);
layout->addWidget(new QLabel(QString::number(tabId)));
mTabWidget->addTab(newTab, QString::number(tabId));
}
void MainWindow::tabCloseRequested(int index)
{
mTabWidget->removeTab(index);
}
/******************************************************************************/
/******************************** MAIN PROGRAM ********************************/
/******************************************************************************/
int main(int argc, char ** argv)
{
QApplication app(argc, argv);
MainWindow mainWindow;
mainWindow.show();
mainWindow.raise();
return app.exec();
}
#ifndef RADIX_RADIXWIDGETS_EXAMPLE_RADIXTABWIDGET_HH_
#define RADIX_RADIXWIDGETS_EXAMPLE_RADIXTABWIDGET_HH_
#include <QMainWindow>
#include <QWidget>
#include "radixwidgets/tabwidget.hh"
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
private:
radix::TabWidget* mTabWidget;
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
public slots:
void addTabRequested();
void tabCloseRequested(int);
};
#endif // RADIX_RADIXWIDGETS_EXAMPLE_RADIXTABWIDGET_HH_
#include "radixwidgets/tabwidget.hh"
#include <iostream>
#include <QTabBar>
#include <QToolButton>
#include <QLabel>
#include <QPushButton>
namespace radix
{
TabWidget::TabWidget(QWidget *parent)
: QTabWidget(parent)
{
// we want this tabs to be closable
setTabsClosable(true);
//
// create a 'new tab' button
QPushButton* newButton = new QPushButton("+", this);
newButton->setObjectName("tabs_new_tab_button");
newButton->setToolTip("Add new tab");
newButton->setMaximumWidth(25);
addTab(new QLabel(""), QString(""));
QWidget* newTabWidget = widget(0);
newTabWidget->setObjectName("tabwidget_new_tab");
tabBar()->setTabButton(0, QTabBar::RightSide, newButton);
// this is require on mac to hide the close button on the first tab
QWidget * temp = tabBar()->tabButton(0, QTabBar::LeftSide);
if(temp) temp->hide();
setTabEnabled(0, false);
// set inactive index to avoid selecting the new tab button
setCurrentIndex(-1);
// forward pushbutton signal
connect(newButton
, SIGNAL(clicked(bool))
, this
, SIGNAL(addTabRequested()));
}
} // namespace radix
#ifndef RADIX_RADIXWIDGETS_TABWIDGET_HH_
#define RADIX_RADIXWIDGETS_TABWIDGET_HH_
#include <QTabWidget>
namespace radix
{
/**
* * @brief The RouteTabs class
* * Tabs displaying each route
* */
class TabWidget : public QTabWidget
{
Q_OBJECT
public:
TabWidget(QWidget* parent=0);
signals:
void addTabRequested();
}; // class TabWidget
} // namespace radix
#endif /** RADIX_RADIXWIDGETS_TABWIDGET_HH_ */
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