Skip to content

Commit

Permalink
Adding --open-dir flag, hotkeys, many screenshots.
Browse files Browse the repository at this point in the history
  • Loading branch information
john-philipp committed Jan 2, 2025
1 parent 669b0ff commit ca4e2be
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/MainFrame.ui
Original file line number Diff line number Diff line change
Expand Up @@ -1525,6 +1525,9 @@
<property name="text">
<string>Center view</string>
</property>
<property name="shortcut">
<string>Ctrl+g</string>
</property>
</action>
<action name="actionShowImage">
<property name="text">
Expand Down Expand Up @@ -1580,6 +1583,9 @@
<property name="text">
<string>screenshot</string>
</property>
<property name="shortcut">
<string>Ctrl+B</string>
</property>
</action>
</widget>
<customwidgets>
Expand Down
26 changes: 25 additions & 1 deletion src/labeler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,37 @@

#include <glow/GlCapabilities.h>

#define FLAG_OPEN_DIR "--open-dir"

std::map<std::string, std::string> parseArgs(int argc, char** argv) {
std::map<std::string, std::string> parsedArgs;

for (int i = 1; i < argc; i++) {
std::string flag = argv[i];
if (flag == FLAG_OPEN_DIR) {
if (argc > i) {
parsedArgs[FLAG_OPEN_DIR] = argv[i++ + 1];
}
}
}

return parsedArgs;
}

int main(int argc, char** argv) {
QApplication app(argc, argv);

Mainframe frame;
auto parsedArgs = parseArgs(argc, argv);

if (parsedArgs.find(FLAG_OPEN_DIR) != parsedArgs.end()) {
auto dir = parsedArgs[FLAG_OPEN_DIR];
std::cout << "Opening dir: " << dir << std::endl;
frame.open(QString::fromStdString(dir));
}

frame.show();
frame.resize(1200, 900);

// std::cout << glow::GlCapabilities::getInstance() << std::endl;

return app.exec();
Expand Down
33 changes: 32 additions & 1 deletion src/widget/Mainframe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,18 @@
#include <boost/lexical_cast.hpp>
#include <fstream>
#include <iostream>
#include <unistd.h>
#include <limits.h>
#include <map>

#include "../data/label_utils.h"
#include "../data/misc.h"

#include <iostream>
#include <chrono>
#include <iomanip>
#include <sstream>

using namespace glow;

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

connect(ui.actionScreenshot, &QAction::triggered, [this]() {
QImage img = ui.mViewportXYZ->grabFrameBuffer();

auto now = std::chrono::system_clock::now();
std::time_t now_time_t = std::chrono::system_clock::to_time_t(now);

// Convert to tm struct for formatting
std::tm now_tm = *std::localtime(&now_time_t);

// Create a stringstream to format the timestamp
std::ostringstream oss;
oss << "screenshot-" << std::put_time(&now_tm, "%Y-%m-%dT%H:%M:%S") << ".png";
img.save(QString::fromStdString(oss.str()));
img.save("screenshot.png");
QApplication::clipboard()->setImage(img);
});
Expand Down Expand Up @@ -505,6 +523,10 @@ void Mainframe::closeEvent(QCloseEvent* event) {
}

void Mainframe::open() {
this->open(nullptr);
}

void Mainframe::open(QString dir) {
if (readerFuture_.valid()) readerFuture_.wait();

if (mChangesSinceLastSave) {
Expand All @@ -520,8 +542,13 @@ void Mainframe::open() {
}
}

QString retValue =
QString retValue;
if (dir == nullptr) {
retValue =
QFileDialog::getExistingDirectory(this, "Select scan directory", lastDirectory, QFileDialog::ShowDirsOnly);
} else {
retValue = dir;
}

if (!retValue.isNull()) {
QDir base_dir(retValue);
Expand Down Expand Up @@ -1220,3 +1247,7 @@ void Mainframe::updateLabelButtons() {
index - std::floor((double)index / btnsPerRow) * btnsPerRow);
}
}

void Mainframe::setLastDirectory(QString lastDirectory) {
this->lastDirectory = lastDirectory;
}
3 changes: 2 additions & 1 deletion src/widget/Mainframe.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ class Mainframe : public QMainWindow {

public slots:
void open();
void open(QString dir);
void save();
void changeRadius(int radius);
void changeMode(int mode, bool checked);

void updateFiltering(bool value);
void labelBtnReleased(QWidget*);
void setLastDirectory(QString lastDirectory);

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

void readConfig();

void initializeIcons();

void updateMovingStatus(bool isMoving);
Expand Down

0 comments on commit ca4e2be

Please sign in to comment.