MCPcopy Create free account
hub / github.com/KDE/labplot / ExamplesWidget

Method ExamplesWidget

src/frontend/examples/ExamplesWidget.cpp:29–88  ·  view source on GitHub ↗

! \class ExamplesWidget \brief Widget showing all available example projects. \ingroup frontend */

Source from the content-addressed store, hash-verified

27 \ingroup frontend
28 */
29ExamplesWidget::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

Callers

nothing calls this directly

Calls 14

groupFunction · 0.85
setToolTipMethod · 0.80
setIconSizeMethod · 0.80
heightMethod · 0.80
setPlaceholderTextMethod · 0.80
QStringClass · 0.50
setIconMethod · 0.45
pixmapMethod · 0.45
setFocusMethod · 0.45
collectionNamesMethod · 0.45
isEmptyMethod · 0.45
setCurrentIndexMethod · 0.45

Tested by

no test coverage detected