示例#1
0
void tst_QTabBar::testCurrentChanged()
{
    QFETCH(int, tabToSet);
    QFETCH(int, expectedCount);
    QTabBar tabBar;
    QSignalSpy spy(&tabBar, SIGNAL(currentChanged(int)));
    tabBar.addTab("Tab1");
    tabBar.addTab("Tab2");
    QCOMPARE(tabBar.currentIndex(), 0);
    tabBar.setCurrentIndex(tabToSet);
    QCOMPARE(tabBar.currentIndex(), tabToSet);
    QCOMPARE(spy.count(), expectedCount);
}
示例#2
0
void tst_QTabBar::removeTab()
{
    QTabBar tabbar;

    QFETCH(int, currentIndex);
    QFETCH(int, deleteIndex);
    tabbar.addTab("foo");
    tabbar.addTab("bar");
    tabbar.addTab("baz");
    tabbar.setCurrentIndex(currentIndex);
    QSignalSpy spy(&tabbar, SIGNAL(currentChanged(int)));
    tabbar.removeTab(deleteIndex);
    QTEST(spy.count(), "spyCount");
    QTEST(tabbar.currentIndex(), "finalIndex");
}
void FancyTabWidget::MakeTabBar(QTabBar::Shape shape, bool text, bool icons,
                                bool fancy) {
  QTabBar* bar = new QTabBar(this);
  bar->setShape(shape);
  bar->setDocumentMode(true);
  bar->setUsesScrollButtons(true);
  bar->setElideMode(Qt::ElideRight);

  if (shape == QTabBar::RoundedWest) {
    bar->setIconSize(QSize(22, 22));
  }

  if (fancy) {
    bar->setStyle(proxy_style_.get());
  }

  if (shape == QTabBar::RoundedNorth)
    top_layout_->insertWidget(0, bar);
  else
    side_layout_->insertWidget(0, bar);

  foreach (const Item& item, items_) {
    if (item.type_ != Item::Type_Tab)
      continue;

    QString label = item.tab_label_;
    if (shape == QTabBar::RoundedWest) {
      label = QFontMetrics(font()).elidedText(label, Qt::ElideMiddle, 100);
    }

    int tab_id = -1;
    if (icons && text)
      tab_id = bar->addTab(item.tab_icon_, label);
    else if (icons)
      tab_id = bar->addTab(item.tab_icon_, QString());
    else if (text)
      tab_id = bar->addTab(label);

    // Adds tooltips only in Tabs mode or IconOnlyTabs mode
    // TODO in tab mode, show only if not elided, complicated since this doesn't inherit from QTabWidget
    if (shape == QTabBar::RoundedNorth && ((!text && icons) || (text && !icons)))
      bar->setTabToolTip(tab_id, item.tab_label_);
  }

  bar->setCurrentIndex(stack_->currentIndex());
  connect(bar, SIGNAL(currentChanged(int)), SLOT(ShowWidget(int)));
  tab_bar_ = bar;
}
示例#4
0
void FancyTabWidget::MakeTabBar(QTabBar::Shape shape, bool text, bool icons,
                                bool fancy) {
  QTabBar* bar = new QTabBar(this);
  bar->setShape(shape);
  bar->setDocumentMode(true);
  bar->setUsesScrollButtons(true);

  if (shape == QTabBar::RoundedWest) {
    bar->setIconSize(QSize(22, 22));
  }

  if (fancy) {
    bar->setStyle(proxy_style_.data());
  }

  if (shape == QTabBar::RoundedNorth)
    top_layout_->insertWidget(0, bar);
  else
    side_layout_->insertWidget(0, bar);

  foreach (const Item& item, items_) {
    if (item.type_ != Item::Type_Tab)
      continue;

    QString label = item.tab_label_;
    if (shape == QTabBar::RoundedWest) {
      label = QFontMetrics(font()).elidedText(label, Qt::ElideMiddle, 100);
    }

    int tab_id = -1;
    if (icons && text)
      tab_id = bar->addTab(item.tab_icon_, label);
    else if (icons)
      tab_id = bar->addTab(item.tab_icon_, QString());
    else if (text)
      tab_id = bar->addTab(label);

    bar->setTabToolTip(tab_id, item.tab_label_);
  }

  bar->setCurrentIndex(stack_->currentIndex());
  connect(bar, SIGNAL(currentChanged(int)), SLOT(ShowWidget(int)));
  tab_bar_ = bar;
}
示例#5
0
void tst_QTabBar::selectionBehaviorOnRemove()
{
    QFETCH(QTabBar::SelectionBehavior, selectionBehavior);
    QFETCH(int, tabs);
    QFETCH(IntList, select);
    QFETCH(IntList, remove);
    QFETCH(int, expected);

    QTabBar tabbar;
    tabbar.setSelectionBehaviorOnRemove(selectionBehavior);
    while(--tabs >= 0)
        tabbar.addTab(QString::number(tabs));
    QCOMPARE(tabbar.currentIndex(), 0);
    while(!select.isEmpty())
        tabbar.setCurrentIndex(select.takeFirst());
    while(!remove.isEmpty())
        tabbar.removeTab(remove.takeFirst());
    QVERIFY(tabbar.count() > 0);
    QCOMPARE(tabbar.currentIndex(), expected);
}
Qtilities::CoreGui::WidgetLoggerEngineFrontend::WidgetLoggerEngineFrontend(WidgetLoggerEngine::MessageDisplaysFlag message_displays_flag,
                                                                           Qt::ToolBarArea toolbar_area,
                                                                           QWidget *parent) : QMainWindow(parent)
{
    d = new WidgetLoggerEngineFrontendPrivateData;
    d->message_displays_flag = message_displays_flag;

    // When only one message display is present we don't create it as a tab widget.
    if (message_displays_flag == WidgetLoggerEngine::AllMessagesPlainTextEdit ||
            message_displays_flag == WidgetLoggerEngine::IssuesPlainTextEdit ||
            message_displays_flag == WidgetLoggerEngine::WarningsPlainTextEdit ||
            message_displays_flag == WidgetLoggerEngine::ErrorsPlainTextEdit) {

        MessagesPlainTextEditTab* new_tab = new MessagesPlainTextEditTab(0,toolbar_area);
        d->message_displays[message_displays_flag] = new_tab;
        setCentralWidget(new_tab);
    } else {
        int info_index = -1;
        int issues_index = -1;
        int warning_index = -1;
        int error_index = -1;

        // Create needed tabs:
        if (d->message_displays_flag & WidgetLoggerEngine::AllMessagesPlainTextEdit) {
            MessagesPlainTextEditTab* new_tab = new MessagesPlainTextEditTab(0,toolbar_area);
            d->message_displays[WidgetLoggerEngine::AllMessagesPlainTextEdit] = new_tab;
            QDockWidget* new_dock = new QDockWidget("Messages");

            // We don't want users to be able to close the individual log
            // dock widgets since there is no way to get them back then
            // until the application is restarted.
            QDockWidget::DockWidgetFeatures features = new_dock->features();
            features &= ~QDockWidget::DockWidgetClosable;
            new_dock->setFeatures(features);

            d->message_display_docks[WidgetLoggerEngine::AllMessagesPlainTextEdit] = new_dock;
            connect(new_dock,SIGNAL(visibilityChanged(bool)),SLOT(handle_dockVisibilityChanged(bool)));
            new_dock->setWidget(new_tab);
            addDockWidget(Qt::BottomDockWidgetArea,new_dock);

            info_index = 0;
        }

        if (d->message_displays_flag & WidgetLoggerEngine::IssuesPlainTextEdit) {
            MessagesPlainTextEditTab* new_tab = new MessagesPlainTextEditTab(0,toolbar_area);
            d->message_displays[WidgetLoggerEngine::IssuesPlainTextEdit] = new_tab;
            QDockWidget* new_dock = new QDockWidget("Issues");

            // We don't want users to be able to close the individual log
            // dock widgets since there is no way to get them back then
            // until the application is restarted.
            QDockWidget::DockWidgetFeatures features = new_dock->features();
            features &= ~QDockWidget::DockWidgetClosable;
            new_dock->setFeatures(features);

            d->message_display_docks[WidgetLoggerEngine::IssuesPlainTextEdit] = new_dock;
            connect(new_dock,SIGNAL(visibilityChanged(bool)),SLOT(handle_dockVisibilityChanged(bool)));
            new_dock->setWidget(new_tab);
            addDockWidget(Qt::BottomDockWidgetArea,new_dock);

            if (d->message_displays_flag & WidgetLoggerEngine::AllMessagesPlainTextEdit)
                issues_index = 1;
            else
                issues_index = 0;
        }

        if (d->message_displays_flag & WidgetLoggerEngine::WarningsPlainTextEdit) {
            MessagesPlainTextEditTab* new_tab = new MessagesPlainTextEditTab(0,toolbar_area);
            d->message_displays[WidgetLoggerEngine::WarningsPlainTextEdit] = new_tab;
            QDockWidget* new_dock = new QDockWidget("Warnings");

            // We don't want users to be able to close the individual log
            // dock widgets since there is no way to get them back then
            // until the application is restarted.
            QDockWidget::DockWidgetFeatures features = new_dock->features();
            features &= ~QDockWidget::DockWidgetClosable;
            new_dock->setFeatures(features);

            d->message_display_docks[WidgetLoggerEngine::WarningsPlainTextEdit] = new_dock;
            connect(new_dock,SIGNAL(visibilityChanged(bool)),SLOT(handle_dockVisibilityChanged(bool)));
            new_dock->setWidget(new_tab);
            addDockWidget(Qt::BottomDockWidgetArea,new_dock);

            if (d->message_displays_flag & WidgetLoggerEngine::AllMessagesPlainTextEdit && d->message_displays_flag & WidgetLoggerEngine::IssuesPlainTextEdit)
                warning_index = 2;
            else if (d->message_displays_flag & WidgetLoggerEngine::AllMessagesPlainTextEdit)
                warning_index = 1;
            else
                warning_index = 0;
        }

        if (d->message_displays_flag & WidgetLoggerEngine::ErrorsPlainTextEdit) {
            MessagesPlainTextEditTab* new_tab = new MessagesPlainTextEditTab(0,toolbar_area);
            d->message_displays[WidgetLoggerEngine::ErrorsPlainTextEdit] = new_tab;
            QDockWidget* new_dock = new QDockWidget("Errors");

            // We don't want users to be able to close the individual log
            // dock widgets since there is no way to get them back then
            // until the application is restarted.
            QDockWidget::DockWidgetFeatures features = new_dock->features();
            features &= ~QDockWidget::DockWidgetClosable;
            new_dock->setFeatures(features);

            d->message_display_docks[WidgetLoggerEngine::ErrorsPlainTextEdit] = new_dock;
            connect(new_dock,SIGNAL(visibilityChanged(bool)),SLOT(handle_dockVisibilityChanged(bool)));
            new_dock->setWidget(new_tab);
            addDockWidget(Qt::BottomDockWidgetArea,new_dock);

            if (d->message_displays_flag & WidgetLoggerEngine::AllMessagesPlainTextEdit && d->message_displays_flag & WidgetLoggerEngine::IssuesPlainTextEdit && d->message_displays_flag & WidgetLoggerEngine::WarningsPlainTextEdit)
                error_index = 3;
            else if (d->message_displays_flag & WidgetLoggerEngine::AllMessagesPlainTextEdit && d->message_displays_flag & WidgetLoggerEngine::WarningsPlainTextEdit)
                error_index = 2;
            else if (d->message_displays_flag & WidgetLoggerEngine::AllMessagesPlainTextEdit && d->message_displays_flag & WidgetLoggerEngine::IssuesPlainTextEdit)
                error_index = 2;
            else if (d->message_displays_flag & WidgetLoggerEngine::AllMessagesPlainTextEdit)
                error_index = 1;
            else if (d->message_displays_flag & WidgetLoggerEngine::WarningsPlainTextEdit)
                error_index = 1;
            else if (d->message_displays_flag & WidgetLoggerEngine::IssuesPlainTextEdit)
                error_index = 1;
            else
                error_index = 0;
        }

        for (int i = 1; i < d->message_display_docks.count(); ++i)
            tabifyDockWidget(d->message_display_docks.values().at(i-1),d->message_display_docks.values().at(i));

        QList<QTabBar *> tabList = findChildren<QTabBar *>();
        if (!tabList.isEmpty()) {
            QTabBar *tabBar = tabList.at(0);
            tabBar->setCurrentIndex(0);
            tabBar->setShape(QTabBar::RoundedSouth);

            if (info_index != -1)
                tabBar->setTabIcon(info_index,QIcon(qti_icon_INFO_12x12));
            if (issues_index != -1)
                tabBar->setTabIcon(issues_index,QIcon(qti_icon_WARNING_12x12));
            if (warning_index != -1)
                tabBar->setTabIcon(warning_index,QIcon(qti_icon_WARNING_12x12));
            if (error_index != -1)
                tabBar->setTabIcon(error_index,QIcon(qti_icon_ERROR_12x12));
        }
    }
}