Some refactoring for #128.
This commit is contained in:
parent
58532fc45d
commit
faf7cde796
2 changed files with 34 additions and 28 deletions
|
@ -286,6 +286,21 @@ int TabWidget::addBrowser(bool move_after_current, bool make_active, const QUrl
|
||||||
#endif
|
#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) {
|
void TabWidget::removeTab(int index, bool clear_from_memory) {
|
||||||
if (clear_from_memory) {
|
if (clear_from_memory) {
|
||||||
widget(index)->deleteLater();
|
widget(index)->deleteLater();
|
||||||
|
@ -297,6 +312,7 @@ void TabWidget::removeTab(int index, bool clear_from_memory) {
|
||||||
int TabWidget::addTab(TabContent *widget, const QIcon &icon, const QString &label, const TabBar::TabType &type) {
|
int TabWidget::addTab(TabContent *widget, const QIcon &icon, const QString &label, const TabBar::TabType &type) {
|
||||||
const int index = QTabWidget::addTab(widget, icon, label);
|
const int index = QTabWidget::addTab(widget, icon, label);
|
||||||
tabBar()->setTabType(index, type);
|
tabBar()->setTabType(index, type);
|
||||||
|
indentTabText(index);
|
||||||
|
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
@ -304,6 +320,7 @@ int TabWidget::addTab(TabContent *widget, const QIcon &icon, const QString &labe
|
||||||
int TabWidget::addTab(TabContent *widget, const QString &label, const TabBar::TabType &type) {
|
int TabWidget::addTab(TabContent *widget, const QString &label, const TabBar::TabType &type) {
|
||||||
const int index = QTabWidget::addTab(widget, label);
|
const int index = QTabWidget::addTab(widget, label);
|
||||||
tabBar()->setTabType(index, type);
|
tabBar()->setTabType(index, type);
|
||||||
|
indentTabText(index);
|
||||||
|
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
@ -311,6 +328,7 @@ int TabWidget::addTab(TabContent *widget, const QString &label, const TabBar::Ta
|
||||||
int TabWidget::insertTab(int index, QWidget *widget, const QIcon &icon, const QString &label, const TabBar::TabType &type) {
|
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);
|
const int tab_index = QTabWidget::insertTab(index, widget, icon, label);
|
||||||
tabBar()->setTabType(tab_index, type);
|
tabBar()->setTabType(tab_index, type);
|
||||||
|
indentTabText(index);
|
||||||
|
|
||||||
return tab_index;
|
return tab_index;
|
||||||
}
|
}
|
||||||
|
@ -318,35 +336,20 @@ int TabWidget::insertTab(int index, QWidget *widget, const QIcon &icon, const QS
|
||||||
int TabWidget::insertTab(int index, QWidget *widget, const QString &label, const TabBar::TabType &type) {
|
int TabWidget::insertTab(int index, QWidget *widget, const QString &label, const TabBar::TabType &type) {
|
||||||
const int tab_index = QTabWidget::insertTab(index, widget, label);
|
const int tab_index = QTabWidget::insertTab(index, widget, label);
|
||||||
tabBar()->setTabType(tab_index, type);
|
tabBar()->setTabType(tab_index, type);
|
||||||
|
indentTabText(index);
|
||||||
|
|
||||||
return tab_index;
|
return tab_index;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TabWidget::changeIcon(int index, const QIcon &new_icon) {
|
void TabWidget::changeIcon(int index, const QIcon &new_icon) {
|
||||||
setTabIcon(index, new_icon);
|
setTabIcon(index, new_icon);
|
||||||
|
indentTabText(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.
|
|
||||||
if (!tabText(index).startsWith(QSL(" "))) {
|
|
||||||
setTabText(index, QSL(" ") + tabText(index));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TabWidget::changeTitle(int index, const QString &new_title) {
|
void TabWidget::changeTitle(int index, const QString &new_title) {
|
||||||
setTabText(index, TextFactory::shorten(new_title));
|
setTabText(index, TextFactory::shorten(new_title));
|
||||||
setTabToolTip(index, new_title);
|
setTabToolTip(index, new_title);
|
||||||
|
indentTabText(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.
|
|
||||||
if (!tabText(index).startsWith(QSL(" "))) {
|
|
||||||
setTabText(index, QSL(" ") + tabText(index));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TabWidget::fixContentsAfterMove(int from, int to) {
|
void TabWidget::fixContentsAfterMove(int from, int to) {
|
||||||
|
|
|
@ -89,24 +89,14 @@ class TabWidget : public QTabWidget {
|
||||||
void tabRemoved(int index);
|
void tabRemoved(int index);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
// Fixes tabs indexes.
|
|
||||||
void fixContentsAfterMove(int from, int to);
|
|
||||||
|
|
||||||
// Called when number of tab pages changes.
|
// Called when number of tab pages changes.
|
||||||
void checkTabBarVisibility();
|
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.
|
// Tab closing.
|
||||||
bool closeTab(int index);
|
bool closeTab(int index);
|
||||||
void closeAllTabsExceptCurrent();
|
void closeAllTabsExceptCurrent();
|
||||||
void closeAllTabs();
|
void closeAllTabs();
|
||||||
|
|
||||||
// Opens main menu.
|
|
||||||
void openMainMenu();
|
|
||||||
|
|
||||||
// Displays download manager.
|
// Displays download manager.
|
||||||
void showDownloadManager();
|
void showDownloadManager();
|
||||||
|
|
||||||
|
@ -123,7 +113,20 @@ class TabWidget : public QTabWidget {
|
||||||
// General method for adding WebBrowsers.
|
// General method for adding WebBrowsers.
|
||||||
int addBrowser(bool move_after_current, bool make_active, const QUrl &initial_url = QUrl());
|
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:
|
private:
|
||||||
|
void indentTabText(int index);
|
||||||
|
|
||||||
PlainToolButton *m_btnMainMenu;
|
PlainToolButton *m_btnMainMenu;
|
||||||
QMenu *m_menuMain;
|
QMenu *m_menuMain;
|
||||||
FeedMessageViewer *m_feedMessageViewer;
|
FeedMessageViewer *m_feedMessageViewer;
|
||||||
|
|
Loading…
Add table
Reference in a new issue