Skip to content

Commit ca4e2be

Browse files
author
john-philipp
committed
Adding --open-dir flag, hotkeys, many screenshots.
1 parent 669b0ff commit ca4e2be

4 files changed

Lines changed: 65 additions & 3 deletions

File tree

src/MainFrame.ui

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1525,6 +1525,9 @@
15251525
<property name="text">
15261526
<string>Center view</string>
15271527
</property>
1528+
<property name="shortcut">
1529+
<string>Ctrl+g</string>
1530+
</property>
15281531
</action>
15291532
<action name="actionShowImage">
15301533
<property name="text">
@@ -1580,6 +1583,9 @@
15801583
<property name="text">
15811584
<string>screenshot</string>
15821585
</property>
1586+
<property name="shortcut">
1587+
<string>Ctrl+B</string>
1588+
</property>
15831589
</action>
15841590
</widget>
15851591
<customwidgets>

src/labeler.cpp

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,37 @@
44

55
#include <glow/GlCapabilities.h>
66

7+
#define FLAG_OPEN_DIR "--open-dir"
8+
9+
std::map<std::string, std::string> parseArgs(int argc, char** argv) {
10+
std::map<std::string, std::string> parsedArgs;
11+
12+
for (int i = 1; i < argc; i++) {
13+
std::string flag = argv[i];
14+
if (flag == FLAG_OPEN_DIR) {
15+
if (argc > i) {
16+
parsedArgs[FLAG_OPEN_DIR] = argv[i++ + 1];
17+
}
18+
}
19+
}
20+
21+
return parsedArgs;
22+
}
23+
724
int main(int argc, char** argv) {
825
QApplication app(argc, argv);
926

1027
Mainframe frame;
28+
auto parsedArgs = parseArgs(argc, argv);
29+
30+
if (parsedArgs.find(FLAG_OPEN_DIR) != parsedArgs.end()) {
31+
auto dir = parsedArgs[FLAG_OPEN_DIR];
32+
std::cout << "Opening dir: " << dir << std::endl;
33+
frame.open(QString::fromStdString(dir));
34+
}
35+
1136
frame.show();
1237
frame.resize(1200, 900);
13-
1438
// std::cout << glow::GlCapabilities::getInstance() << std::endl;
1539

1640
return app.exec();

src/widget/Mainframe.cpp

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,18 @@
99
#include <boost/lexical_cast.hpp>
1010
#include <fstream>
1111
#include <iostream>
12+
#include <unistd.h>
13+
#include <limits.h>
1214
#include <map>
1315

1416
#include "../data/label_utils.h"
1517
#include "../data/misc.h"
1618

19+
#include <iostream>
20+
#include <chrono>
21+
#include <iomanip>
22+
#include <sstream>
23+
1724
using namespace glow;
1825

1926
// see https://stackoverflow.com/a/24349347
@@ -477,6 +484,17 @@ Mainframe::Mainframe() : mChangesSinceLastSave(false) {
477484

478485
connect(ui.actionScreenshot, &QAction::triggered, [this]() {
479486
QImage img = ui.mViewportXYZ->grabFrameBuffer();
487+
488+
auto now = std::chrono::system_clock::now();
489+
std::time_t now_time_t = std::chrono::system_clock::to_time_t(now);
490+
491+
// Convert to tm struct for formatting
492+
std::tm now_tm = *std::localtime(&now_time_t);
493+
494+
// Create a stringstream to format the timestamp
495+
std::ostringstream oss;
496+
oss << "screenshot-" << std::put_time(&now_tm, "%Y-%m-%dT%H:%M:%S") << ".png";
497+
img.save(QString::fromStdString(oss.str()));
480498
img.save("screenshot.png");
481499
QApplication::clipboard()->setImage(img);
482500
});
@@ -505,6 +523,10 @@ void Mainframe::closeEvent(QCloseEvent* event) {
505523
}
506524

507525
void Mainframe::open() {
526+
this->open(nullptr);
527+
}
528+
529+
void Mainframe::open(QString dir) {
508530
if (readerFuture_.valid()) readerFuture_.wait();
509531

510532
if (mChangesSinceLastSave) {
@@ -520,8 +542,13 @@ void Mainframe::open() {
520542
}
521543
}
522544

523-
QString retValue =
545+
QString retValue;
546+
if (dir == nullptr) {
547+
retValue =
524548
QFileDialog::getExistingDirectory(this, "Select scan directory", lastDirectory, QFileDialog::ShowDirsOnly);
549+
} else {
550+
retValue = dir;
551+
}
525552

526553
if (!retValue.isNull()) {
527554
QDir base_dir(retValue);
@@ -1220,3 +1247,7 @@ void Mainframe::updateLabelButtons() {
12201247
index - std::floor((double)index / btnsPerRow) * btnsPerRow);
12211248
}
12221249
}
1250+
1251+
void Mainframe::setLastDirectory(QString lastDirectory) {
1252+
this->lastDirectory = lastDirectory;
1253+
}

src/widget/Mainframe.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,14 @@ class Mainframe : public QMainWindow {
2525

2626
public slots:
2727
void open();
28+
void open(QString dir);
2829
void save();
2930
void changeRadius(int radius);
3031
void changeMode(int mode, bool checked);
3132

3233
void updateFiltering(bool value);
3334
void labelBtnReleased(QWidget*);
35+
void setLastDirectory(QString lastDirectory);
3436

3537
signals:
3638
void readerStarted();
@@ -53,7 +55,6 @@ class Mainframe : public QMainWindow {
5355
void closeEvent(QCloseEvent* event);
5456

5557
void readConfig();
56-
5758
void initializeIcons();
5859

5960
void updateMovingStatus(bool isMoving);

0 commit comments

Comments
 (0)