Functional menu for web browser.

This commit is contained in:
Martin Rotter 2013-11-07 20:51:24 +01:00
parent dbbedc7b74
commit 075aaf34d8
3 changed files with 48 additions and 5 deletions

View File

@ -176,6 +176,10 @@ void FormMain::createConnections() {
this, SLOT(loadWebBrowserMenu(int)));
connect(m_ui->m_actionCloseCurrentTab, SIGNAL(triggered()),
m_ui->m_tabWidget, SLOT(closeCurrentTab()));
connect(m_ui->m_actionAddBrowser, SIGNAL(triggered()),
m_ui->m_tabWidget, SLOT(addEmptyBrowser()));
connect(m_ui->m_actionCloseAllTabs, SIGNAL(triggered()),
m_ui->m_tabWidget, SLOT(closeAllTabsExceptCurrent()));
}
void FormMain::loadWebBrowserMenu(int index) {

View File

@ -76,14 +76,50 @@ void TabWidget::setupIcons() {
m_cornerButton->setIcon(IconThemeFactory::getInstance()->fromTheme("list-add"));
}
void TabWidget::closeTab(int index) {
bool TabWidget::closeTab(int index) {
if (tabBar()->tabType(index) == TabBar::Closable) {
removeTab(index);
return true;
}
else {
return false;
}
}
void TabWidget::closeCurrentTab() {
closeTab(currentIndex());
bool TabWidget::closeCurrentTab() {
return closeTab(currentIndex());
}
void TabWidget::closeAllTabsExceptCurrent() {
// Close tabs after active tab.
int index_of_active = currentIndex();
int total_count = count();
int iterative_index = 0;
while (total_count-- > 0) {
if (iterative_index < index_of_active) {
// Deleting tab on the left from the active one.
if (closeTab(iterative_index)) {
// We successfully deleted that LEFT tab.
index_of_active--;
}
else {
// We reached "non-closable" tab, go forward.
iterative_index++;
}
}
else if (iterative_index > index_of_active) {
// Deleting tab on the right from the active one.
if (!closeTab(iterative_index)) {
// We reached "non-closable" tab, go forward.
iterative_index++;
}
}
else {
// We iterate through active tab now, no deleting;
iterative_index++;
}
}
}
void TabWidget::removeTab(int index) {

View File

@ -59,8 +59,11 @@ class TabWidget : public QTabWidget {
void changeIcon(int index, const QIcon &new_icon);
// Closes tab with given index and deletes contained widget.
void closeTab(int index);
void closeCurrentTab();
bool closeTab(int index);
bool closeCurrentTab();
// Closes all "closable" tabs except the active tab.
void closeAllTabsExceptCurrent();
// Adds new WebBrowser tab to global TabWidget.
int addEmptyBrowser();