Skip to content

Commit

Permalink
Some refactoring for #128.
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Rotter committed Jul 13, 2017
1 parent 58532fc commit faf7cde
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 28 deletions.
39 changes: 21 additions & 18 deletions src/gui/tabwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,21 @@ int TabWidget::addBrowser(bool move_after_current, bool make_active, const QUrl
#endif
}

void TabWidget::indentTabText(int index){
#if defined (Q_OS_MACOS)
if (tabBar()->tabType(index) != TabBar::FeedReader && !tabIcon(index).isNull()) {
// We have closable tab with some icon, fix the title.
const QString text = tabText(index);

if (!text.startsWith(QSL(" "))) {
setTabText(index, QSL(" ") + text);
}
}
#else
Q_UNUSED(index)
#endif
}

void TabWidget::removeTab(int index, bool clear_from_memory) {
if (clear_from_memory) {
widget(index)->deleteLater();
Expand All @@ -297,56 +312,44 @@ void TabWidget::removeTab(int index, bool clear_from_memory) {
int TabWidget::addTab(TabContent *widget, const QIcon &icon, const QString &label, const TabBar::TabType &type) {
const int index = QTabWidget::addTab(widget, icon, label);
tabBar()->setTabType(index, type);
indentTabText(index);

return index;
}

int TabWidget::addTab(TabContent *widget, const QString &label, const TabBar::TabType &type) {
const int index = QTabWidget::addTab(widget, label);
tabBar()->setTabType(index, type);
indentTabText(index);

return index;
}

int TabWidget::insertTab(int index, QWidget *widget, const QIcon &icon, const QString &label, const TabBar::TabType &type) {
const int tab_index = QTabWidget::insertTab(index, widget, icon, label);
tabBar()->setTabType(tab_index, type);
indentTabText(index);

return tab_index;
}

int TabWidget::insertTab(int index, QWidget *widget, const QString &label, const TabBar::TabType &type) {
const int tab_index = QTabWidget::insertTab(index, widget, label);
tabBar()->setTabType(tab_index, type);
indentTabText(index);

return tab_index;
}

void TabWidget::changeIcon(int index, const QIcon &new_icon) {
setTabIcon(index, new_icon);

#if defined (Q_OS_MACOS)
if (tabBar()->tabType(index) != TabBar::FeedReader && !tabIcon(index).isNull()) {
// We have closable tab with some icon, fix the title.
if (!tabText(index).startsWith(QSL(" "))) {
setTabText(index, QSL(" ") + tabText(index));
}
}
#endif
indentTabText(index);
}

void TabWidget::changeTitle(int index, const QString &new_title) {
setTabText(index, TextFactory::shorten(new_title));
setTabToolTip(index, new_title);

#if defined (Q_OS_MACOS)
if (tabBar()->tabType(index) != TabBar::FeedReader && !tabIcon(index).isNull()) {
// We have closable tab with some icon, fix the title.
if (!tabText(index).startsWith(QSL(" "))) {
setTabText(index, QSL(" ") + tabText(index));
}
}
#endif
indentTabText(index);
}

void TabWidget::fixContentsAfterMove(int from, int to) {
Expand Down
23 changes: 13 additions & 10 deletions src/gui/tabwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,24 +89,14 @@ class TabWidget : public QTabWidget {
void tabRemoved(int index);

public slots:
// Fixes tabs indexes.
void fixContentsAfterMove(int from, int to);

// Called when number of tab pages changes.
void checkTabBarVisibility();

// Changes icon/text of the tab.
void changeTitle(int index, const QString &new_title);
void changeIcon(int index, const QIcon &new_icon);

// Tab closing.
bool closeTab(int index);
void closeAllTabsExceptCurrent();
void closeAllTabs();

// Opens main menu.
void openMainMenu();

// Displays download manager.
void showDownloadManager();

Expand All @@ -123,7 +113,20 @@ class TabWidget : public QTabWidget {
// General method for adding WebBrowsers.
int addBrowser(bool move_after_current, bool make_active, const QUrl &initial_url = QUrl());

private slots:
// Fixes tabs indexes.
void fixContentsAfterMove(int from, int to);

// Changes icon/text of the tab.
void changeTitle(int index, const QString &new_title);
void changeIcon(int index, const QIcon &new_icon);

// Opens main menu.
void openMainMenu();

private:
void indentTabText(int index);

PlainToolButton *m_btnMainMenu;
QMenu *m_menuMain;
FeedMessageViewer *m_feedMessageViewer;
Expand Down

0 comments on commit faf7cde

Please sign in to comment.