ViewSettingsPage::ViewSettingsPage(QWidget* parent) : SettingsPageBase(parent), m_tabs() { QVBoxLayout* topLayout = new QVBoxLayout(this); topLayout->setMargin(0); topLayout->setSpacing(KDialog::spacingHint()); KTabWidget* tabWidget = new KTabWidget(this); // Initialize 'Icons' tab ViewSettingsTab* iconsTab = new ViewSettingsTab(ViewSettingsTab::IconsMode, tabWidget); tabWidget->addTab(iconsTab, KIcon("view-list-icons"), i18nc("@title:tab", "Icons")); connect(iconsTab, SIGNAL(changed()), this, SIGNAL(changed())); // Initialize 'Compact' tab ViewSettingsTab* compactTab = new ViewSettingsTab(ViewSettingsTab::CompactMode, tabWidget); tabWidget->addTab(compactTab, KIcon("view-list-details"), i18nc("@title:tab", "Compact")); connect(compactTab, SIGNAL(changed()), this, SIGNAL(changed())); // Initialize 'Details' tab ViewSettingsTab* detailsTab = new ViewSettingsTab(ViewSettingsTab::DetailsMode, tabWidget); tabWidget->addTab(detailsTab, KIcon("view-list-tree"), i18nc("@title:tab", "Details")); connect(detailsTab, SIGNAL(changed()), this, SIGNAL(changed())); m_tabs.append(iconsTab); m_tabs.append(compactTab); m_tabs.append(detailsTab); topLayout->addWidget(tabWidget, 0, 0); }
void testCloseFirstTab() { // Test inspired by #170470, but the bug only happened when calling setTabText // in slotCurrentChanged so the real unit test for that bug is in konqueror. KTabWidget w; w.setAutomaticResizeTabs(true); w.resize(300, 400); // Send the pending resize event (resize() only sets Qt::WA_PendingResizeEvent) QResizeEvent e(w.size(), QSize()); QApplication::sendEvent(&w, &e); QString prefix = "This is a long prefix for the tab title. "; for (int i = 0; i < 6; ++i) w.insertTab(i, new QWidget, prefix+QString::number(i)); w.removeTab(0); for (int i = 0; i < 5; ++i) { //kDebug() << i << w.tabText(i); QCOMPARE(w.tabText(i), QString(prefix+QString::number(i+1))); } w.removeTab(0); for (int i = 0; i < 4; ++i) { //kDebug() << i << w.tabText(i); QCOMPARE(w.tabText(i), QString(prefix+QString::number(i+2))); } }
/** * Sets up the documentation group. * @param margin The margin of the group. */ void ClassifierListPage::setupDocumentationGroup(int margin) { m_pDocGB = new QGroupBox(i18n("Documentation"), this); QVBoxLayout* docLayout = new QVBoxLayout(m_pDocGB); docLayout->setSpacing(10); docLayout->setMargin(margin); if (m_itemType == ot_Operation) { m_pDocTE = new KTextEdit(); m_pCodeTE = new CodeTextEdit(); KTabWidget* tabWidget = new KTabWidget(); tabWidget->addTab(m_pDocTE, i18n("Comment")); tabWidget->addTab(m_pCodeTE, i18n("Source Code")); docLayout->addWidget(tabWidget); } else { m_pDocTE = new KTextEdit(); docLayout->addWidget(m_pDocTE); } }
void testSetHidden() { KTabWidget w; w.insertTab(0, new QWidget, "a tab"); QVERIFY(!w.isTabBarHidden()); w.show(); QVERIFY(!w.isTabBarHidden()); w.setTabBarHidden(true); QVERIFY(w.isTabBarHidden()); }
void KPluginSelectionWidget::embeddPluginKCMs(KPluginInfo *plugininfo, bool checked) { // if we have Services for the plugin we should be able to // create KCM(s) QApplication::setOverrideCursor(Qt::WaitCursor); if(plugininfo->kcmServices().size() > 1) { // we need a tabwidget KTabWidget *tabwidget = new KTabWidget(d->widgetstack); tabwidget->setEnabled(checked); int id = d->widgetstack->addWidget(tabwidget); d->kps->configPage(id); d->widgetIDs[plugininfo->pluginName()] = id; for(QValueList< KService::Ptr >::ConstIterator it = plugininfo->kcmServices().begin(); it != plugininfo->kcmServices().end(); ++it) { if(!(*it)->noDisplay()) { KCModuleInfo moduleinfo(*it); QWidget *module = insertKCM(tabwidget, moduleinfo); tabwidget->addTab(module, moduleinfo.moduleName()); } } } else { if(!plugininfo->kcmServices().front()->noDisplay()) { KCModuleInfo moduleinfo(plugininfo->kcmServices().front()); QWidget *module = insertKCM(d->widgetstack, moduleinfo); module->setEnabled(checked); int id = d->widgetstack->addWidget(module); d->kps->configPage(id); d->widgetIDs[plugininfo->pluginName()] = id; } } QApplication::restoreOverrideCursor(); }
void testMoveTab() { // Test inspired by #170470 and #177036 (title messup). // Then expanded to include the problem of #159295 (focus loss). QWidget topLevel; QComboBox* combo = new QComboBox(&topLevel); combo->setEditable(true); KTabWidget* w = new KTabWidget(&topLevel); w->setAutomaticResizeTabs(true); w->resize(300, 400); QResizeEvent e(w->size(), QSize()); QApplication::sendEvent(w, &e); QString prefix = "This is a long prefix for the tab title. "; KLineEdit* lineEdits[4]; for (int i = 0; i < 4; ++i) { QWidget* page = new QWidget; page->setObjectName(QString::number(i)); lineEdits[i] = new KLineEdit(page); // a widget that can take focus lineEdits[i]->setObjectName("LineEdit"+QString::number(i)); w->insertTab(i, page, prefix+QString::number(i)); //kDebug() << i << w->tabText(i); } topLevel.show(); // Necessary after show(), otherwise topLevel.focusWidget() returns NULL QApplication::setActiveWindow(&topLevel); // Make sure the tab order is so that the combo gets focus after this tab QWidget::setTabOrder(lineEdits[0], combo->lineEdit()); QWidget::setTabOrder(combo->lineEdit(), lineEdits[1]); w->setCurrentIndex(0); lineEdits[0]->setFocus(); QCOMPARE(topLevel.focusWidget()->objectName(), lineEdits[0]->objectName()); QVERIFY(lineEdits[0]->isVisible()); w->moveTab(0,3); //for (int i = 0; i < 4; ++i) //kDebug() << i << w->tabText(i); QCOMPARE(w->tabText(0), QString(prefix+QString::number(1))); QCOMPARE(w->tabText(1), QString(prefix+QString::number(2))); QCOMPARE(w->tabText(2), QString(prefix+QString::number(3))); QCOMPARE(w->tabText(3), QString(prefix+QString::number(0))); // Did the focus switch to the lineEdit, due to removeTab+insertTab? Whoops. QCOMPARE(topLevel.focusWidget()->objectName(), lineEdits[0]->objectName()); w->moveTab(3,0); QCOMPARE(topLevel.focusWidget()->objectName(), lineEdits[0]->objectName()); for (int i = 0; i < 4; ++i) { //kDebug() << i << w->tabText(i); QCOMPARE(w->tabText(i), QString(prefix+QString::number(i))); } }