-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathicons.cpp
More file actions
699 lines (621 loc) · 24.4 KB
/
icons.cpp
File metadata and controls
699 lines (621 loc) · 24.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
#include "icons.h"
#include "icongrid.h"
#include "iconmodel.h"
#include "ui_icons.h"
#include <QApplication>
#include <QClipboard>
#include <QDebug>
#include <QFileDialog>
#include <QMessageBox>
#include <QSettings>
// Stringify macros for build number
#define STRINGIFY(x) #x
#define TOSTRING(x) STRINGIFY(x)
// Generated icon list headers - Bootstrap
#include "library/lib_bootstrap_fill_16.h"
#include "library/lib_bootstrap_regular_16.h"
// Generated icon list headers - Tabler
#include "library/lib_tabler_filled_24.h"
#include "library/lib_tabler_outline_24.h"
// Generated icon list headers - Fluent UI (multiple sizes)
#include "library/lib_fluent_filled_10.h"
#include "library/lib_fluent_filled_12.h"
#include "library/lib_fluent_filled_16.h"
#include "library/lib_fluent_filled_20.h"
#include "library/lib_fluent_filled_24.h"
#include "library/lib_fluent_filled_28.h"
#include "library/lib_fluent_filled_32.h"
#include "library/lib_fluent_filled_48.h"
#include "library/lib_fluent_regular_10.h"
#include "library/lib_fluent_regular_12.h"
#include "library/lib_fluent_regular_16.h"
#include "library/lib_fluent_regular_20.h"
#include "library/lib_fluent_regular_24.h"
#include "library/lib_fluent_regular_28.h"
#include "library/lib_fluent_regular_32.h"
#include "library/lib_fluent_regular_48.h"
// Generated icon list headers - Breeze (all sizes per category)
#include "library/lib_breeze_actions_12.h"
#include "library/lib_breeze_actions_16.h"
#include "library/lib_breeze_actions_22.h"
#include "library/lib_breeze_actions_32.h"
#include "library/lib_breeze_actions_48.h"
#include "library/lib_breeze_actions_64.h"
#include "library/lib_breeze_apps_16.h"
#include "library/lib_breeze_apps_22.h"
#include "library/lib_breeze_apps_32.h"
#include "library/lib_breeze_apps_48.h"
#include "library/lib_breeze_apps_64.h"
#include "library/lib_breeze_devices_16.h"
#include "library/lib_breeze_devices_22.h"
#include "library/lib_breeze_devices_32.h"
#include "library/lib_breeze_devices_64.h"
#include "library/lib_breeze_mimetypes_16.h"
#include "library/lib_breeze_mimetypes_22.h"
#include "library/lib_breeze_mimetypes_32.h"
#include "library/lib_breeze_mimetypes_64.h"
#include "library/lib_breeze_places_16.h"
#include "library/lib_breeze_places_22.h"
#include "library/lib_breeze_places_32.h"
#include "library/lib_breeze_places_48.h"
#include "library/lib_breeze_places_64.h"
#include "library/lib_breeze_status_16.h"
#include "library/lib_breeze_status_22.h"
#include "library/lib_breeze_status_32.h"
#include "library/lib_breeze_status_64.h"
// Generated icon list headers - Oxygen (Bitmap)
#include "library/bitmap/lib_oxygen_128.h"
#include "library/bitmap/lib_oxygen_16.h"
#include "library/bitmap/lib_oxygen_22.h"
#include "library/bitmap/lib_oxygen_256.h"
#include "library/bitmap/lib_oxygen_32.h"
#include "library/bitmap/lib_oxygen_48.h"
#include "library/bitmap/lib_oxygen_64.h"
// Generated icon list headers - Oxygen5 (Bitmap)
#include "library/bitmap/lib_oxygen5_128.h"
#include "library/bitmap/lib_oxygen5_16.h"
#include "library/bitmap/lib_oxygen5_22.h"
#include "library/bitmap/lib_oxygen5_256.h"
#include "library/bitmap/lib_oxygen5_32.h"
#include "library/bitmap/lib_oxygen5_48.h"
#include "library/bitmap/lib_oxygen5_64.h"
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), m_ui(new Ui::MainWindow) {
m_ui->setupUi(this);
// Setup icon size action group
m_iconSizeGroup = new QActionGroup(this);
m_iconSizeGroup->addAction(m_ui->actionSmallIcons);
m_iconSizeGroup->addAction(m_ui->actionMediumIcons);
m_iconSizeGroup->addAction(m_ui->actionLargeIcons);
m_iconSizeGroup->setExclusive(true);
// Add permanent icon count label to status bar
m_iconCountLabel = new QLabel(this);
statusBar()->addPermanentWidget(m_iconCountLabel);
setupConnections();
registerBuiltinCollections();
loadCollections();
}
MainWindow::~MainWindow() = default;
void MainWindow::setupConnections() {
// Menu actions
connect(m_ui->actionCopySvg, &QAction::triggered, this, &MainWindow::onCopySvg);
connect(m_ui->actionCopyPng, &QAction::triggered, this, &MainWindow::onCopyPng);
connect(m_ui->actionExport, &QAction::triggered, this, &MainWindow::onExport);
connect(m_ui->actionAbout, &QAction::triggered, this, &MainWindow::onAbout);
// View actions
connect(m_ui->actionSmallIcons, &QAction::triggered, this, &MainWindow::setSmallIcons);
connect(m_ui->actionMediumIcons, &QAction::triggered, this, &MainWindow::setMediumIcons);
connect(m_ui->actionLargeIcons, &QAction::triggered, this, &MainWindow::setLargeIcons);
// Icon grid signals
connect(m_ui->iconGrid, &IconGrid::iconSelected, this, &MainWindow::onIconSelected);
// Connect model signals for icon count updates
connect(m_ui->iconGrid->model(), &IconModel::iconListChanged, this, &MainWindow::updateIconCount);
connect(m_ui->iconGrid->model(), &IconModel::filterChanged, this, &MainWindow::updateIconCount);
}
void MainWindow::registerBuiltinCollections() {
auto ®istry = IconCollectionRegistry::instance();
// Bootstrap Icons - single size 16
registry.registerCollection({ "bootstrap", "Bootstrap", { 16 },
{ { IconStyle::Outline, [](int) { return new BootstrapRegular16IconList(); } },
{ IconStyle::Filled, [](int) { return new BootstrapFill16IconList(); } } } });
// Tabler Icons - single size 24
registry.registerCollection({ "tabler", "Tabler", { 24 },
{ { IconStyle::Outline, [](int) { return new TablerOutline24IconList(); } },
{ IconStyle::Filled, [](int) { return new TablerFilled24IconList(); } } } });
// Fluent UI Icons - multiple sizes with Regular (Outline) + Filled
registry.registerCollection({ "fluent", "Fluent UI", { 10, 12, 16, 20, 24, 28, 32, 48 },
{ { IconStyle::Outline, [](int size) -> SVGIconList* {
switch (size) {
case 10: return new FluentRegular10IconList();
case 12: return new FluentRegular12IconList();
case 16: return new FluentRegular16IconList();
case 20: return new FluentRegular20IconList();
case 24: return new FluentRegular24IconList();
case 28: return new FluentRegular28IconList();
case 32: return new FluentRegular32IconList();
case 48: return new FluentRegular48IconList();
default: return new FluentRegular24IconList();
}
} },
{ IconStyle::Filled, [](int size) -> SVGIconList* {
switch (size) {
case 10: return new FluentFilled10IconList();
case 12: return new FluentFilled12IconList();
case 16: return new FluentFilled16IconList();
case 20: return new FluentFilled20IconList();
case 24: return new FluentFilled24IconList();
case 28: return new FluentFilled28IconList();
case 32: return new FluentFilled32IconList();
case 48: return new FluentFilled48IconList();
default: return new FluentFilled24IconList();
}
} } } });
// Breeze Icons (KDE) - organized by category with multiple sizes
registry.registerCollection({ "breeze-actions", "Breeze Actions", { 12, 16, 22, 32, 48, 64 },
{ { IconStyle::Outline, [](int size) -> SVGIconList* {
switch (size) {
case 12: return new BreezeActions12IconList();
case 16: return new BreezeActions16IconList();
case 22: return new BreezeActions22IconList();
case 32: return new BreezeActions32IconList();
case 48: return new BreezeActions48IconList();
case 64: return new BreezeActions64IconList();
default: return new BreezeActions22IconList();
}
} } } });
registry.registerCollection({ "breeze-apps", "Breeze Apps", { 16, 22, 32, 48, 64 },
{ { IconStyle::Outline, [](int size) -> SVGIconList* {
switch (size) {
case 16: return new BreezeApps16IconList();
case 22: return new BreezeApps22IconList();
case 32: return new BreezeApps32IconList();
case 48: return new BreezeApps48IconList();
case 64: return new BreezeApps64IconList();
default: return new BreezeApps22IconList();
}
} } } });
registry.registerCollection({ "breeze-places", "Breeze Places", { 16, 22, 32, 48, 64 },
{ { IconStyle::Outline, [](int size) -> SVGIconList* {
switch (size) {
case 16: return new BreezePlaces16IconList();
case 22: return new BreezePlaces22IconList();
case 32: return new BreezePlaces32IconList();
case 48: return new BreezePlaces48IconList();
case 64: return new BreezePlaces64IconList();
default: return new BreezePlaces22IconList();
}
} } } });
registry.registerCollection({ "breeze-status", "Breeze Status", { 16, 22, 32, 64 },
{ { IconStyle::Outline, [](int size) -> SVGIconList* {
switch (size) {
case 16: return new BreezeStatus16IconList();
case 22: return new BreezeStatus22IconList();
case 32: return new BreezeStatus32IconList();
case 64: return new BreezeStatus64IconList();
default: return new BreezeStatus22IconList();
}
} } } });
registry.registerCollection({ "breeze-devices", "Breeze Devices", { 16, 22, 32, 64 },
{ { IconStyle::Outline, [](int size) -> SVGIconList* {
switch (size) {
case 16: return new BreezeDevices16IconList();
case 22: return new BreezeDevices22IconList();
case 32: return new BreezeDevices32IconList();
case 64: return new BreezeDevices64IconList();
default: return new BreezeDevices22IconList();
}
} } } });
registry.registerCollection({ "breeze-mimetypes", "Breeze Mimetypes", { 16, 22, 32, 64 },
{ { IconStyle::Outline, [](int size) -> SVGIconList* {
switch (size) {
case 16: return new BreezeMimetypes16IconList();
case 22: return new BreezeMimetypes22IconList();
case 32: return new BreezeMimetypes32IconList();
case 64: return new BreezeMimetypes64IconList();
default: return new BreezeMimetypes22IconList();
}
} } } });
// Oxygen Icons (Bitmap) - multiple sizes available
registry.registerBitmapCollection({ "oxygen", "Oxygen Icons",
{ 16, 22, 32, 48, 64, 128, 256 },
[](int size) -> BitmapIconList * {
switch (size) {
case 16:
return new Oxygen16IconList();
case 22:
return new Oxygen22IconList();
case 32:
return new Oxygen32IconList();
case 48:
return new Oxygen48IconList();
case 64:
return new Oxygen64IconList();
case 128:
return new Oxygen128IconList();
case 256:
return new Oxygen256IconList();
default:
return new Oxygen32IconList();
}
} });
// Oxygen5 Icons (Bitmap) - multiple sizes available
registry.registerBitmapCollection({ "oxygen5", "Oxygen5 Icons",
{ 16, 22, 32, 48, 64, 128, 256 },
[](int size) -> BitmapIconList * {
switch (size) {
case 16:
return new Oxygen516IconList();
case 22:
return new Oxygen522IconList();
case 32:
return new Oxygen532IconList();
case 48:
return new Oxygen548IconList();
case 64:
return new Oxygen564IconList();
case 128:
return new Oxygen5128IconList();
case 256:
return new Oxygen5256IconList();
default:
return new Oxygen532IconList();
}
} });
}
void MainWindow::loadCollections() {
auto ®istry = IconCollectionRegistry::instance();
auto collections = registry.collections();
auto bitmapCollections = registry.bitmapCollections();
// Build list of collection names for the toolbar (SVG + Bitmap)
QStringList names;
for (const auto &coll : collections) {
names.append(coll.displayName);
}
for (const auto &coll : bitmapCollections) {
names.append(coll.displayName);
}
// Set up the toolbar's collection dropdown
auto *toolbar = m_ui->iconGrid->findChild<IconToolBar *>();
if (toolbar) {
toolbar->setCollections(names);
connect(toolbar, &IconToolBar::collectionChanged, this, &MainWindow::onCollectionChanged);
connect(toolbar, &IconToolBar::styleChanged, this, &MainWindow::onStyleChanged);
connect(toolbar, &IconToolBar::bitmapSizeChanged, this, &MainWindow::onBitmapSizeChanged);
connect(toolbar, &IconToolBar::svgSizeChanged, this, &MainWindow::onSvgSizeChanged);
// Restore colors from preferences
QSettings settings;
QColor fillColor = settings.value("fillColor", QColor(Qt::black)).value<QColor>();
QColor bgColor = settings.value("backgroundColor", QColor(Qt::transparent)).value<QColor>();
toolbar->setFillColor(fillColor);
toolbar->setBackgroundColor(bgColor);
// Save colors when changed
connect(toolbar, &IconToolBar::fillColorChanged, this, [](const QColor &color) {
QSettings settings;
settings.setValue("fillColor", color);
});
connect(toolbar, &IconToolBar::backgroundColorChanged, this, [](const QColor &color) {
QSettings settings;
settings.setValue("backgroundColor", color);
});
}
// Load the first available collection with default style (Outline)
if (!collections.isEmpty()) {
m_currentCollectionId = collections.first().id;
m_currentStyle = IconStyle::Outline;
m_isBitmapCollection = false;
loadCurrentCollection();
// Set stroke mode (Tabler = stroke-based, others = fill-based)
bool isTabler = m_currentCollectionId.startsWith("tabler");
m_ui->iconGrid->setStrokeMode(!isTabler);
// Update available styles in toolbar
if (toolbar) {
updateAvailableStyles();
// Show stroke slider for SVG Outline/TwoTone styles
toolbar->setStrokeWidthVisible(true);
}
}
// Count total icons
int totalIcons = 0;
for (const auto &coll : collections) {
auto *tempList = registry.createIconList(coll.id, IconStyle::Outline, coll.defaultSize());
if (tempList) {
totalIcons += tempList->getCount();
delete tempList;
}
}
for (const auto &coll : bitmapCollections) {
auto *tempList = registry.createBitmapList(coll.id, coll.defaultSize());
if (tempList) {
totalIcons += tempList->getCount();
delete tempList;
}
}
int totalCollections = collections.size() + bitmapCollections.size();
statusBar()->showMessage(tr("Loaded %1 collections with %2 icons").arg(totalCollections).arg(totalIcons));
}
void MainWindow::loadCurrentCollection() {
auto ®istry = IconCollectionRegistry::instance();
if (m_isBitmapCollection) {
auto *list = registry.createBitmapList(m_currentCollectionId, m_currentBitmapSize);
if (list) {
m_bitmapLists.push_back(std::unique_ptr<BitmapIconList>(list));
m_currentList = list;
m_ui->iconGrid->setIconList(list);
}
} else {
auto *list = registry.createIconList(m_currentCollectionId, m_currentStyle, m_currentSvgSize);
if (list) {
m_iconLists.push_back(std::unique_ptr<SVGIconList>(list));
m_currentList = list;
m_ui->iconGrid->setIconList(list);
}
}
}
void MainWindow::updateAvailableStyles() {
auto *toolbar = m_ui->iconGrid->toolBar();
if (!toolbar)
return;
auto ®istry = IconCollectionRegistry::instance();
// Update bitmap mode for toolbar and preview
toolbar->setBitmapMode(m_isBitmapCollection);
m_ui->iconGrid->preview()->setBitmapMode(m_isBitmapCollection);
if (m_isBitmapCollection) {
// Bitmap collections have Color/Grayscale styles
toolbar->setStyles({ "Color", "Grayscale" });
// Also update available sizes
const BitmapCollection *coll = registry.findBitmapCollection(m_currentCollectionId);
if (coll) {
toolbar->setBitmapSizes(coll->availableSizes);
}
} else {
// SVG collections have Outline/Filled/TwoTone styles
const IconCollection *coll = registry.findCollection(m_currentCollectionId);
if (!coll)
return;
QStringList styles;
for (IconStyle style : coll->availableStyles()) {
styles.append(iconStyleToString(style));
}
// Add TwoTone if both Outline and Filled are available
if (coll->hasStyle(IconStyle::Outline) && coll->hasStyle(IconStyle::Filled)) {
if (!styles.contains("TwoTone"))
styles.append("TwoTone");
}
toolbar->setStyles(styles);
// Set available SVG sizes for this collection
toolbar->setSvgSizes(coll->availableSizes);
// Set current size to collection's default if not already set
if (m_currentSvgSize <= 0 || !coll->availableSizes.contains(m_currentSvgSize)) {
m_currentSvgSize = coll->defaultSize();
}
}
}
void MainWindow::onCollectionChanged(const QString &name) {
auto ®istry = IconCollectionRegistry::instance();
// Check if it's a bitmap collection first
for (const auto &coll : registry.bitmapCollections()) {
if (coll.displayName == name) {
m_currentCollectionId = coll.id;
m_isBitmapCollection = true;
m_currentBitmapSize = coll.defaultSize();
loadCurrentCollection();
updateAvailableStyles();
// Hide stroke width slider for bitmap collections
auto *toolbar = m_ui->iconGrid->toolBar();
if (toolbar)
toolbar->setStrokeWidthVisible(false);
return;
}
}
// Otherwise it's an SVG collection
auto collections = registry.collections();
for (const auto &coll : collections) {
if (coll.displayName == name) {
m_currentCollectionId = coll.id;
m_isBitmapCollection = false;
// Reset to Outline style when changing collection
m_currentStyle = IconStyle::Outline;
loadCurrentCollection();
updateAvailableStyles();
// Update stroke mode and visibility for SVG outline/twotone styles
bool isTabler = m_currentCollectionId.startsWith("tabler");
m_ui->iconGrid->setStrokeMode(!isTabler); // Tabler = stroke-based, others = fill-based
auto *toolbar = m_ui->iconGrid->toolBar();
if (toolbar) {
bool showStroke = (m_currentStyle == IconStyle::Outline || m_currentStyle == IconStyle::TwoTone);
toolbar->setStrokeWidthVisible(showStroke);
}
break;
}
}
}
void MainWindow::onStyleChanged(const QString &styleName) {
if (m_isBitmapCollection) {
// Handle bitmap styles (Color/Grayscale)
bool grayscale = (styleName == "Grayscale");
m_ui->iconGrid->model()->setGrayscale(grayscale);
} else {
// Handle SVG styles
m_currentStyle = stringToIconStyle(styleName);
loadCurrentCollection();
// Show/hide tone color button for TwoTone mode
auto *toolbar = m_ui->iconGrid->toolBar();
if (toolbar) {
toolbar->setTwoToneMode(m_currentStyle == IconStyle::TwoTone);
// Show stroke width slider for Outline and TwoTone styles
bool showStroke = (m_currentStyle == IconStyle::Outline || m_currentStyle == IconStyle::TwoTone);
toolbar->setStrokeWidthVisible(showStroke);
}
}
}
void MainWindow::onBitmapSizeChanged(int size) {
if (m_isBitmapCollection) {
m_currentBitmapSize = size;
loadCurrentCollection();
}
}
void MainWindow::onSvgSizeChanged(int size) {
if (!m_isBitmapCollection && size > 0) {
m_currentSvgSize = size;
loadCurrentCollection();
}
}
void MainWindow::onIconSelected(int index, const QString &name, const QStringList &tags, const QString &category) {
m_selectedIndex = index;
m_selectedName = name;
// Build status message with metadata
QString message = tr("Selected: %1").arg(name);
if (!category.isEmpty()) {
message += tr(" | Category: %1").arg(category);
}
if (!tags.isEmpty()) {
// Show first few tags to avoid overflow
QStringList displayTags = tags.mid(0, 5);
message += tr(" | Tags: %1").arg(displayTags.join(", "));
if (tags.size() > 5) {
message += tr(" (+%1 more)").arg(tags.size() - 5);
}
}
statusBar()->showMessage(message);
}
void MainWindow::onIconDoubleClicked(int index, const QString &name) {
Q_UNUSED(index)
if (!m_currentList || index < 0)
return;
if (m_isBitmapCollection) {
// Copy PNG on double-click for bitmap collections
QPixmap pixmap = m_ui->iconGrid->model()->getIconPixmap(index);
if (!pixmap.isNull()) {
QApplication::clipboard()->setPixmap(pixmap);
statusBar()->showMessage(tr("Copied PNG: %1").arg(name), 3000);
}
} else {
// Copy SVG on double-click for SVG collections
auto *svg = static_cast<SVGIconList *>(m_currentList);
QString source = svg->getSource(index);
QApplication::clipboard()->setText(source);
statusBar()->showMessage(tr("Copied SVG: %1").arg(name), 3000);
}
}
void MainWindow::onCopySvg() {
if (!m_currentList || m_selectedIndex < 0)
return;
if (m_isBitmapCollection) {
statusBar()->showMessage(tr("SVG not available for bitmap icons"), 3000);
return;
}
// Use model to get SVG with proper fill color and stroke width applied
QString source = m_ui->iconGrid->model()->getIconSvg(m_selectedIndex);
QApplication::clipboard()->setText(source);
statusBar()->showMessage(tr("Copied SVG to clipboard"), 3000);
}
void MainWindow::onCopyPng() {
if (m_selectedIndex >= 0) {
QPixmap pixmap = m_ui->iconGrid->model()->getIconPixmap(m_selectedIndex);
if (!pixmap.isNull()) {
QApplication::clipboard()->setPixmap(pixmap);
statusBar()->showMessage(tr("Copied PNG to clipboard"), 3000);
}
}
}
void MainWindow::onExport() {
if (m_currentList && m_selectedIndex >= 0) {
QString defaultExt = m_isBitmapCollection ? ".png" : ".svg";
QString defaultName = m_selectedName + defaultExt;
QString filter = m_isBitmapCollection
? tr("PNG Files (*.png);;All Files (*)")
: tr("SVG Files (*.svg);;PNG Files (*.png);;All Files (*)");
QString filename = QFileDialog::getSaveFileName(
this,
tr("Export Icon"),
defaultName,
filter);
if (!filename.isEmpty()) {
if (filename.endsWith(".svg", Qt::CaseInsensitive) && !m_isBitmapCollection) {
auto *svgList = static_cast<SVGIconList *>(m_currentList);
QString svg = svgList->getSource(m_selectedIndex);
QFile file(filename);
if (file.open(QIODevice::WriteOnly | QIODevice::Text)) {
file.write(svg.toUtf8());
file.close();
statusBar()->showMessage(tr("Exported to %1").arg(filename), 3000);
}
} else if (filename.endsWith(".png", Qt::CaseInsensitive)) {
QPixmap pixmap = m_ui->iconGrid->model()->getIconPixmap(m_selectedIndex);
if (!pixmap.isNull()) {
pixmap.save(filename, "PNG");
statusBar()->showMessage(tr("Exported to %1").arg(filename), 3000);
}
}
}
}
}
void MainWindow::onAbout() {
QMessageBox aboutBox(this);
aboutBox.setWindowTitle(tr("About Icon Viewer"));
aboutBox.setTextFormat(Qt::RichText);
aboutBox.setText(
tr("<p><span style='font-size:18pt; font-weight:600;'>Icon Viewer</span> "
"<span style='font-size:10pt;'>v%1 (%2)</span><br/>"
"<span style='font-size:10pt; font-style:italic;'>Browse, preview, and export icons from popular icon libraries.</span></p>")
.arg(APP_VERSION).arg(TOSTRING(APP_BUILD)));
aboutBox.setInformativeText(
tr("<p><b>Supported Icon Libraries:</b></p>"
"<p><b>SVG Icons:</b><br/>"
"• <a href='https://icons.getbootstrap.com/'>Bootstrap Icons</a> - Open source icon set<br/>"
"• <a href='https://tabler.io/icons'>Tabler Icons</a> - Over 5000 free icons<br/>"
"• <a href='https://github.com/microsoft/fluentui-system-icons'>Fluent UI Icons</a> - Microsoft's icon system<br/>"
"• <a href='https://develop.kde.org/frameworks/breeze-icons/'>Breeze Icons</a> - KDE's icon theme</p>"
"<p><b>Bitmap Icons (PNG):</b><br/>"
"• <a href='https://techbase.kde.org/Projects/Oxygen/Licensing'>Oxygen Icons</a> - Classic KDE icon theme<br/>"
"• <a href='https://invent.kde.org/frameworks/oxygen-icons'>Oxygen5 Icons</a> - Updated Oxygen icons</p>"
"<hr/>"
"<p><b>Written with:</b><br/>"
"• <a href='https://qt.io'>Qt</a> - Cross-platform application framework</p>"
"<p><b>Author:</b> Pawel Piecuch<br/>"
"<b>Copyright</b> © 2024, <i>Komsoft Oprogramowanie</i></p>"
"<hr/>"
"<p><i>If you like this application, you can support my work and further development:</i><br/>"
"<a href='https://www.paypal.com/donate?business=6QXS8MBPKBTTN&item_name=Icon%20Viewer¤cy_code=USD'>Donate with PayPal</a></p>"
"<hr/>"
"<p style='font-size:10pt;'><b>Version:</b> %1<br/>"
"<b>Qt Version:</b> %2<br/>"
"<b>Build:</b> %3 %4</p>")
.arg(qApp->applicationVersion())
.arg(qVersion())
.arg(__DATE__)
.arg(__TIME__));
aboutBox.setStandardButtons(QMessageBox::Ok);
aboutBox.exec();
}
void MainWindow::setSmallIcons() {
m_ui->iconGrid->setIconSize(24);
}
void MainWindow::setMediumIcons() {
m_ui->iconGrid->setIconSize(32);
}
void MainWindow::setLargeIcons() {
m_ui->iconGrid->setIconSize(48);
}
void MainWindow::updateIconCount() {
auto *model = m_ui->iconGrid->model();
int total = model->iconList() ? model->iconList()->getCount() : 0;
int visible = model->rowCount();
QString filter = model->filter();
QString text;
if (filter.isEmpty()) {
text = tr("%1 icons").arg(total);
} else {
text = tr("%1 of %2 icons").arg(visible).arg(total);
}
m_iconCountLabel->setText(text);
}
int main(int argc, char *argv[]) {
QApplication app(argc, argv);
app.setApplicationName("Icon Viewer");
app.setOrganizationName("KomSoft");
app.setApplicationVersion(QString("%1 (%2)").arg(APP_VERSION).arg(TOSTRING(APP_BUILD)));
MainWindow w;
w.setWindowTitle(QString("Icon Viewer v%1 (%2)").arg(APP_VERSION).arg(TOSTRING(APP_BUILD)));
w.show();
return app.exec();
}