! \class ExamplesWidget \brief Widget showing all available example projects. \ingroup frontend */
| 27 | \ingroup frontend |
| 28 | */ |
| 29 | ExamplesWidget::ExamplesWidget(QWidget* parent) |
| 30 | : QWidget(parent) { |
| 31 | ui.setupUi(this); |
| 32 | ui.bInfo->setIcon(QIcon::fromTheme(QLatin1String("help-about"))); |
| 33 | ui.bViewMode->setIcon(QIcon::fromTheme(QLatin1String("view-list-icons"))); |
| 34 | ui.bViewMode->setToolTip(i18n("Switch between icon and list views")); |
| 35 | |
| 36 | ui.lvExamples->setViewMode(QListView::IconMode); |
| 37 | ui.lvExamples->setSelectionMode(QAbstractItemView::SingleSelection); |
| 38 | ui.lvExamples->setWordWrap(true); |
| 39 | ui.lvExamples->setResizeMode(QListWidget::Adjust); |
| 40 | ui.lvExamples->setDragDropMode(QListView::NoDragDrop); |
| 41 | ui.lvExamples->setEditTriggers(QAbstractItemView::NoEditTriggers); |
| 42 | ui.lvExamples->setIconSize(QSize(256, 256)); |
| 43 | connect(ui.lvExamples, &QAbstractItemView::doubleClicked, this, &ExamplesWidget::doubleClicked); |
| 44 | |
| 45 | ui.lPreview->setScaledContents(false); |
| 46 | ui.lPreview->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter); |
| 47 | |
| 48 | const int size = ui.leSearch->height(); |
| 49 | ui.lSearch->setPixmap(QIcon::fromTheme(QLatin1String("edit-find")).pixmap(size, size)); |
| 50 | |
| 51 | QString info = i18n("Enter the keyword you want to search for"); |
| 52 | ui.lSearch->setToolTip(info); |
| 53 | ui.leSearch->setToolTip(info); |
| 54 | ui.leSearch->setPlaceholderText(i18n("Search...")); |
| 55 | ui.leSearch->setFocus(); |
| 56 | |
| 57 | m_manager = ExamplesManager::instance(); |
| 58 | ui.cbCollections->addItems(m_manager->collectionNames()); |
| 59 | |
| 60 | connect(ui.cbCollections, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &ExamplesWidget::collectionChanged); |
| 61 | connect(ui.bInfo, &QPushButton::clicked, this, &ExamplesWidget::showInfo); |
| 62 | connect(ui.bViewMode, &QPushButton::clicked, this, &ExamplesWidget::toggleIconView); |
| 63 | connect(ui.stackedWidget, &QStackedWidget::currentChanged, this, &ExamplesWidget::viewModeChanged); |
| 64 | connect(ui.lwExamples, &QListWidget::itemSelectionChanged, this, &ExamplesWidget::exampleChanged); |
| 65 | |
| 66 | // select the last used collection |
| 67 | KConfigGroup conf = Settings::group(QStringLiteral("ExamplesWidget")); |
| 68 | const QString& collection = conf.readEntry("Collection", QString()); |
| 69 | if (collection.isEmpty()) |
| 70 | ui.cbCollections->setCurrentIndex(0); |
| 71 | else { |
| 72 | for (int i = 0; i < ui.cbCollections->count(); ++i) { |
| 73 | if (ui.cbCollections->itemText(i) == collection) { |
| 74 | ui.cbCollections->setCurrentIndex(i); |
| 75 | break; |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | const QString& colorMap = conf.readEntry("Example", QString()); |
| 80 | auto items = ui.lwExamples->findItems(colorMap, Qt::MatchExactly); |
| 81 | if (items.count() == 1) |
| 82 | ui.lwExamples->setCurrentItem(items.constFirst()); |
| 83 | } |
| 84 | |
| 85 | collectionChanged(ui.cbCollections->currentIndex()); |
| 86 |
nothing calls this directly
no test coverage detected