ui->tableWidget->setColumnWidth(TC_TYPE, 75);
prepareContextMenu();
m_guiTimer->start(100);
- bool active = m_guiTimer->isActive();
- active = ! active;
}
/**
delete ui;
}
-/**
- * initializeHomeializes the program home directory.
- */
-void MainWindow::initializeHome(){
- if (m_homeDir.isEmpty()){
- m_homeDir = QDir::home().absoluteFilePath(".refind");
- }
-
- QDir home(m_homeDir);
- if (!home.exists()){
- if (!home.mkpath(m_homeDir)){
- m_homeDir = home.tempPath() + "/.refind";
- home.mkpath(m_homeDir);
- }
- }
- if (!m_homeDir.endsWith("/"))
- m_homeDir += "/";
- m_storageFile = m_homeDir + "state.conf";
- restoreState();
-}
-
/**
* Starts the about dialog.
*/
dialog.exec();
}
-/**
- * Starts the options dialog.
- */
-void MainWindow::options(){
- DialogOptions dialog(m_contextHandlers, NULL);
- dialog.exec();
-}
-
/**
* Puts the absolute path of the current (selected) file into the clipboard.
*/
return rc;
}
+
+/**
+ * Builds the hash with the global placeholders with their current values.
+ *
+ * @param hash IN/OUT: the placeholders will be appended here
+ */
+void MainWindow::buildGlobalPlaceholders(QMap <QString, QString>& hash){
+
+ hash.insert("filepatterns", ui->comboBoxFilePatterns->currentText());
+ hash.insert("base", m_lastBaseDir.absolutePath());
+ hash.insert("textpattern", addEsc(ui->comboBoxTextPattern->currentText()));
+ hash.insert("dirs", QString::number(m_statistics.m_dirs));
+ hash.insert("files", QString::number(m_statistics.m_files));
+ hash.insert("runtime", QString::number(m_statistics.m_runtimeSeconds, 'g', 3));
+ hash.insert("bytes", QString::number(m_statistics.m_bytes));
+ hash.insert("megabytes",
+ QString::number((double) m_statistics.m_bytes / 1000000));
+ hash.insert("datetime",
+ QDateTime::currentDateTime().toLocalTime().toString("yyyy.MM.dd/hh:mm:ss"));
+}
+
/**
* Gets the content of the given cell as string.
*
}
return rc;
}
-
+/**
+ * Actions while closing the application.
+ */
void MainWindow::closing(){
saveState();
}
handlePlaceholder(ui->comboBoxHeader);
}
+
+/**
+ * initializeHomeializes the program home directory.
+ */
+void MainWindow::initializeHome(){
+ if (m_homeDir.isEmpty()){
+ m_homeDir = QDir::home().absoluteFilePath(".refind");
+ }
+
+ QDir home(m_homeDir);
+ if (!home.exists()){
+ if (!home.mkpath(m_homeDir)){
+ m_homeDir = home.tempPath() + "/.refind";
+ home.mkpath(m_homeDir);
+ }
+ }
+ if (!m_homeDir.endsWith("/"))
+ m_homeDir += "/";
+ m_storageFile = m_homeDir + "state.conf";
+ restoreState();
+}
+
/**
* Informs the instance about some state changes.
*
return ReObserver::SUCCESS;
}
+/**
+ * Starts the options dialog.
+ */
+void MainWindow::options(){
+ DialogOptions dialog(m_contextHandlers, NULL);
+ dialog.exec();
+}
+
+
+/**
+ * Sets the properties of the file finder.
+ *
+ * @param finder OUT: the finder to populate
+ */
+void MainWindow::populateFinder(FileFinder& finder){
+ if (! ui->checkBoxAppend->isChecked()){
+ ui->tableWidget->setRowCount(0);
+ m_statistics.clear();
+ }
+ finder.setObserver(this);
+ finder.setGuiQueue(&this->m_guiQueue);
+ finder.setBaseDir(comboText(ui->comboBoxDirectory));
+ finder.setTable(ui->tableWidget);
+ m_lastBaseDir.cd(comboText(ui->comboBoxDirectory));
+ finder.setMaxSize(comboSize(ui->comboBoxMaxSize));
+ finder.setMinSize(comboSize(ui->comboBoxMinSize));
+ finder.setOlderThan(comboDate(ui->comboBoxOlder));
+ finder.setYoungerThan(comboDate(ui->comboBoxYounger));
+ finder.setMinDepth(comboInt(ui->comboBoxMinDepth, 0));
+ finder.setMaxDepth(comboInt(ui->comboBoxMaxDepth, -1));
+ finder.setMaxHits(comboInt(ui->comboBoxMaxHits, 0x7fffffff));
+ finder.setFiletypes(buildFileTypes());
+ QStringList patterns;
+ QString value = comboText(ui->comboBoxFilePatterns);
+ if (!value.isEmpty())
+ patterns = value.split(",");
+ finder.setPatterns(patterns);
+ value = comboText(ui->comboBoxExcludedDirs);
+ if (value.indexOf('/') >= 0 || value.indexOf('\\') >= 0)
+ guiError(ui->comboBoxExcludedDirs, tr("no path delimiter allowed"));
+ else if (value.indexOf('*') >= 0)
+ guiError(ui->comboBoxExcludedDirs,
+ tr("no patterns allowed. Do not use '*"));
+ else if (!value.isEmpty())
+ patterns = value.split(",");
+ finder.setExcludedDirs(patterns);
+ if (m_errors == 0){
+ prepareTextFind();
+ if (!comboText(ui->comboBoxTextPattern).isEmpty())
+ finder.setTextFinder(&m_textFinder);
+ }
+}
+
/**
* Prepares the context menu of the result table.
*
msgBox.exec();
}
-/**
- * Builds the hash with the global placeholders with their current values.
- *
- * @param hash IN/OUT: the placeholders will be appended here
- */
-void MainWindow::buildGlobalPlaceholders(QMap <QString, QString>& hash){
-
- hash.insert("filepatterns", ui->comboBoxFilePatterns->currentText());
- hash.insert("base", m_lastBaseDir.absolutePath());
- hash.insert("textpattern", addEsc(ui->comboBoxTextPattern->currentText()));
- hash.insert("dirs", QString::number(m_statistics.m_dirs));
- hash.insert("files", QString::number(m_statistics.m_files));
- hash.insert("runtime", QString::number(m_statistics.m_runtimeSeconds, 'g', 3));
- hash.insert("bytes", QString::number(m_statistics.m_bytes));
- hash.insert("megabytes",
- QString::number((double) m_statistics.m_bytes / 1000000));
- hash.insert("datetime",
- QDateTime::currentDateTime().toLocalTime().toString("yyyy.MM.dd/hh:mm:ss"));
-}
/**
* Replaces the placeholders valid in header and footer.
*
storage.close();
}
-/**
- * Sets the properties of the file finder.
- *
- * @param finder OUT: the finder to populate
- */
-void MainWindow::populateFinder(FileFinder& finder){
- if (! ui->checkBoxAppend->isChecked()){
- ui->tableWidget->setRowCount(0);
- m_statistics.clear();
- }
- finder.setObserver(this);
- finder.setGuiQueue(&this->m_guiQueue);
- finder.setBaseDir(comboText(ui->comboBoxDirectory));
- finder.setTable(ui->tableWidget);
- m_lastBaseDir.cd(comboText(ui->comboBoxDirectory));
- finder.setMaxSize(comboSize(ui->comboBoxMaxSize));
- finder.setMinSize(comboSize(ui->comboBoxMinSize));
- finder.setOlderThan(comboDate(ui->comboBoxOlder));
- finder.setYoungerThan(comboDate(ui->comboBoxYounger));
- finder.setMinDepth(comboInt(ui->comboBoxMinDepth, 0));
- finder.setMaxDepth(comboInt(ui->comboBoxMaxDepth, -1));
- finder.setMaxHits(comboInt(ui->comboBoxMaxHits, 0x7fffffff));
- finder.setFiletypes(buildFileTypes());
- QStringList patterns;
- QString value = comboText(ui->comboBoxFilePatterns);
- if (!value.isEmpty())
- patterns = value.split(",");
- finder.setPatterns(patterns);
- value = comboText(ui->comboBoxExcludedDirs);
- if (value.indexOf('/') >= 0 || value.indexOf('\\') >= 0)
- guiError(ui->comboBoxExcludedDirs, tr("no path delimiter allowed"));
- else if (value.indexOf('*') >= 0)
- guiError(ui->comboBoxExcludedDirs,
- tr("no patterns allowed. Do not use '*"));
- else if (!value.isEmpty())
- patterns = value.split(",");
- finder.setExcludedDirs(patterns);
- if (m_errors == 0){
- prepareTextFind();
- if (!comboText(ui->comboBoxTextPattern).isEmpty())
- finder.setTextFinder(&m_textFinder);
- }
-}
-
/**
* Handles the "search" button.
*/
* @param start <code>true</code>: the search should start
*/
void MainWindow::startStop(bool start){
- ui->actionStart->setEnabled(!start);
+ ui->actionStart->setEnabled(!start);
ui->actionStop->setEnabled(start);
ui->pushButtonSearch->setEnabled(! start);
ui->pushButtonSearch2->setEnabled(! start);
* Handles the "search" button.
*/
void MainWindow::stop(){
- m_finder->setStop(true);
+ m_finder->setStop(true);
startStop(false);
}
void about();
void absPathToClipboard();
void baseDirToClipboard();
- void closing();
void clear();
+ void closing();
void exportFiles();
void filePlaceholder();
void footerPlaceholder();
#include "converter.hpp"
#include "mainwindow.hpp"
#include <QRegularExpression>
-#include <QRegExp>
+#include <QPixmap>
/** @file
*
* @param targetDirectory the target directory
* @param sourcePattern the pattern for the files to process
* @param targetType the target image type
+ * @param simpleConversion <code>true</code>: same limits for landscape/portrait/square
+ * @param maxWidth maximal width (only uses in simple mode)
+ * @param maxHeight maximal height (only uses in simple mode)
* @param landscapeX 0 or the given maximal width for landscape format
* @param landscapeY 0 or the given maximal height for landscape format
* @param portraitX 0 or the given maximal width for portrait format
* @param mainWindow the window. Will be used for output
*/
Converter::Converter(const QString& directory, const QString& targetDirectory,
- const QString& sourcePattern, const QString& targetType, int landscapeX,
+ const QString& sourcePattern, const QString& targetType,
+ bool simpleConversion, int maxWidth, int maxHeight, int landscapeX,
int landscapeY, int portraitX, int portraitY, int squareX, int quality,
MainWindow* mainWindow) :
m_dir(directory),
m_imageInfo(
new QRegularExpression(" (PNG|GIF|JPEG) (\\d+)x(\\d+) ")),
m_groupWidth(2),
- m_groupHeight(3){
+ m_groupHeight(3),
+ m_simpleMode(simpleConversion),
+ m_maxWidth(maxWidth),
+ m_maxHeight(maxHeight)
+ {
}
/**
process.close();
}
+/**
+ * Converts an image with a given maximal width and size.
+ *
+ * @param width the width of the image
+ * @param height the height of the image
+ * @param widthNew OUT: the width of the converted image
+ * @param heightNew OUT: the height of the converted image
+ * @return <code>true</code>: the image needs to be converted
+ */
+bool Converter::handleSimple(int width, int height, int& widthNew, int& heightNew)
+{
+ bool doConvert = false;
+ if (width > m_maxWidth){
+ doConvert = true;
+ widthNew = m_maxWidth;
+ heightNew = roundInt((double) height * widthNew / width);
+ if (heightNew > m_maxHeight){
+ heightNew = m_maxHeight;
+ widthNew = roundInt((double) width * heightNew / height);
+ }
+ } else if (height > m_maxHeight){
+ heightNew = m_maxHeight;
+ widthNew = roundInt((double) width * heightNew / height);
+ }
+ return doConvert;
+}
+/**
+ * Converts an image with a given maximal width and size.
+ *
+ * @param width the width of the image
+ * @param height the height of the image
+ * @param widthNew OUT: the width of the converted image
+ * @param heightNew OUT: the height of the converted image
+ * @return <code>true</code>: the image needs to be converted
+ */
+bool Converter::handleUserDefined(int width, int height, int& widthNew, int& heightNew){
+ bool doConvert = false;
+ if (abs(width - height) < 5){
+ // Square format:
+ doConvert = width > m_squareWidth;
+ if (doConvert)
+ widthNew = heightNew = m_squareWidth;
+ }else if (width > height){
+ // Landscape:
+ doConvert = width > m_landscapeWidth || height > m_landscapeHeight;
+ if (doConvert){
+ if (width > m_landscapeWidth && m_landscapeWidth > 0){
+ widthNew = m_landscapeWidth;
+ heightNew = height * m_landscapeWidth / width;
+ }else{
+ heightNew = m_landscapeHeight;
+ widthNew = width * m_landscapeHeight / height;
+ }
+ }
+ }else{
+ // Portrait
+ doConvert = width > m_portraitWidth || height > m_portraitHeight;
+ if (doConvert){
+ if (width > m_portraitWidth && m_portraitWidth > 0){
+ widthNew = m_portraitWidth;
+ heightNew = height * m_portraitWidth / width;
+ }else{
+ heightNew = m_portraitHeight;
+ widthNew = width * m_portraitHeight / height;
+ }
+ }
+ }
+ return doConvert;
+}
+
/**
* @brief Converts one file.
*
QString info;
clock_t start = clock();
if (readProperties(source, width, height, info)){
- bool doConvert = false;
- int widthNew, heightNew;
- if (abs(width - height) < 5){
- // Square format:
- doConvert = width > m_squareWidth;
- if (doConvert)
- widthNew = heightNew = m_squareWidth;
- }else if (width > height){
- // Landscape:
- doConvert = width > m_landscapeWidth || height > m_landscapeHeight;
- if (doConvert){
- if (width > m_landscapeWidth && m_landscapeWidth > 0){
- widthNew = m_landscapeWidth;
- heightNew = height * m_landscapeWidth / width;
- }else{
- heightNew = m_landscapeHeight;
- widthNew = width * m_landscapeHeight / height;
- }
- }
- }else{
- // Portrait
- doConvert = width > m_portraitWidth || height > m_portraitHeight;
- if (doConvert){
- if (width > m_portraitWidth && m_portraitWidth > 0){
- widthNew = m_portraitWidth;
- heightNew = height * m_portraitWidth / width;
- }else{
- heightNew = m_portraitHeight;
- widthNew = width * m_portraitHeight / height;
- }
- }
- }
+ int widthNew = width;
+ int heightNew = height;
+ bool doConvert;
+ if (m_simpleMode)
+ doConvert = handleSimple(width, height, widthNew, heightNew);
+ else
+ doConvert = handleUserDefined(width, height, widthNew, heightNew);
log(
source + " " + info + " " + sizeToString(size)
+ QString(" -> %1x%2 ").arg(widthNew).arg(heightNew));
}
m_mainWindows->logAppendLast(
QString("").sprintf("%.3f sec",
- double(clock() - start) / CLOCKS_PER_SEC));
+ double(clock() - start) / CLOCKS_PER_SEC));
}
/**
}
/**
- * Reads the image properties using the external program "identify".
+ * Reads the image properties.
*
* @param name the filename with path
* @param width OUT: the width of the image
* <code>false</code>: properties not readable
*/
bool Converter::readProperties(const QString& name, int& width, int& height,
+ QString& info){
+ QPixmap image(name);
+
+ width = image.width();
+ height = image.height();
+ bool rc = width != 0 && height != 0;
+ if (! rc)
+ error(tr("unknown format in ") + name);
+ info = QString("%1x%2").arg(width).arg(height);
+ return rc;
+}
+
+/**
+ * Reads the image properties using the external program "identify".
+ *
+ * @param name the filename with path
+ * @param width OUT: the width of the image
+ * @param height OUT: the height of the image
+ * @param info OUT: an info about the image
+ * @return <code>true</code>: success
+ * <code>false</code>: properties not readable
+ */
+bool Converter::readPropertiesByIdentify(const QString& name, int& width, int& height,
QString& info){
QStringList args;
args << name;
class ConverterException {
public:
ConverterException(const QString& message) :
- m_message(message){
+ m_message(message){
}
const QString& message() const{
- return m_message;
+ return m_message;
}
private:
Q_OBJECT
public:
enum State {
- STATE_UNDEF, STATE_STARTING, STATE_SUB_TASK_STOPPED, STATE_READY,
+ STATE_UNDEF, STATE_STARTING, STATE_SUB_TASK_STOPPED, STATE_READY,
};
public:
Converter(const QString& directory, const QString& targetDirectory,
- const QString& sourcePattern, const QString& targetType, int landscapeX,
- int landscapey, int portraitX, int portraitY, int squareX, int quality,
- MainWindow* mainWindows);
+ const QString& sourcePattern, const QString& targetType,
+ bool simpleConversion, int maxWidth, int maxHeight, int landscapeX,
+ int landscapeY, int portraitX, int portraitY, int squareX, int quality,
+ MainWindow* mainWindows);
~Converter();
public:
bool error(const QString& message);
bool log(const QString& message);
void run();
void stop(){
- m_shouldStop = true;
+ m_shouldStop = true;
}
protected:
bool buildArgs();
void changeState(State state, const QString& info);
void convert(const QString& source, const QString& target, int width,
- int height, int widthNew, int heightNew, int quality);
+ int height, int widthNew, int heightNew, int quality);
void convertOneFile(const QString& source, const QString& target,
- qint64 size);
+ qint64 size);
+ bool handleSimple(int width, int height, int& widthNew, int& heightNew);
+ bool handleUserDefined(int width, int height, int& widthNew, int& heightNew);
bool readProperties(const QString& name, int &width, int &height,
- QString &info);
+ QString &info);
+ bool readPropertiesByIdentify(const QString& name, int &width, int &height,
+ QString &info);
private:
QDir m_dir;
QDir m_targetDir;
QRegularExpression* m_imageInfo;
int m_groupWidth;
int m_groupHeight;
+ bool m_simpleMode;
+ int m_maxWidth;
+ int m_maxHeight;
};
#endif // CONVERTER_HPP
QString homeDir = argc > 1 ? argv[1] : "";
QApplication a(argc, argv);
MainWindow w(homeDir);
- w.show();
-
- return a.exec();
+ QObject::connect(&a, SIGNAL(aboutToQuit()), &w, SLOT(closing()));
+ w.show();
+ return a.exec();
}
#include "ui_mainwindow.h"
#include "aboutdialog.hpp"
-const QString VERSION("2015.05.31");
+const QString VERSION("2016.01.15");
/** @class MainWindow mainwindow.hpp "mainwindow.hpp"
*
m_logger(),
m_guiQueue(),
m_guiTimer(new QTimer(this)){
-
- ui->setupUi(this);
- initializeHome();
- startStop(true);
+ ui->setupUi(this);
+ initializeHome();
+ m_logger.buildStandardAppender(I18N::s2b(m_homeDir + OS_SEPARATOR_STR
+ + "reimgconvert").constData());
+ startStop(false);
m_statusMessage = new QLabel(tr("Welcome at reimgconvert"));
statusBar()->addWidget(m_statusMessage);
- connect(ui->actionSelectDestination, SIGNAL(triggered()), this,
- SLOT(selectDestination()));
+ connect(ui->actionSelectTarget, SIGNAL(triggered()), this,
+ SLOT(selectTarget()));
+ connect(ui->actionClear, SIGNAL(triggered()), this, SLOT(clear()));
+ connect(ui->pushButtonClear, SIGNAL(clicked()), this, SLOT(clear()));
+ connect(ui->actionSelectTarget, SIGNAL(triggered()), this,
+ SLOT(selectTarget()));
connect(ui->pushButtonSelectDest, SIGNAL(clicked()), this,
- SLOT(selectDestination()));
+ SLOT(selectTarget()));
connect(ui->actionSelectSource, SIGNAL(triggered()), this,
SLOT(selectSource()));
- connect(ui->pushButtonSelectDest, SIGNAL(clicked()), this,
- SLOT(selectDestination()));
+ connect(ui->pushButtonSelectSource, SIGNAL(clicked()), this,
+ SLOT(selectSource()));
connect(ui->actionAbout, SIGNAL(triggered()), this, SLOT(about()));
- restoreState();
connect(ui->comboBoxTemplate, SIGNAL(currentIndexChanged(const QString&)),
this, SLOT(on_templateChangeIndex(const QString&)));
connect(ui->pushButtonActivate, SIGNAL(clicked()), this, SLOT(activate()));
}
/**
- * Slot when the pushbutton "activate" is clicked.
+ * Starts the about dialog.
*/
-void MainWindow::activate(){
- int width = comboInt(ui->comboBoxMaxWidth, 0);
- int height = comboInt(ui->comboBoxMaxHeight, 0);
- setMaxDimensions(width, height);
+void MainWindow::about(){
+ AboutDialog dialog(VERSION);
+ dialog.exec();
}
/**
- * Sets the maximal dimensions (from the "simple" interface).
- *
- * @param maxWidth the maximal width
- * @param maxHeight the maximal height
+ * Slot when the pushbutton "activate" is clicked.
*/
-void MainWindow::setMaxDimensions(int maxWidth, int maxHeight){
- if (maxWidth > maxHeight){
- ui->comboBoxLandscapeX->setCurrentText(QString::number(maxWidth));
- ui->comboBoxLandscapeY->setCurrentText("*");
- ui->comboBoxPortraitX->setCurrentText("*");
- ui->comboBoxPortraitY->setCurrentText(QString::number(maxHeight));
- ui->comboBoxSquareX->setCurrentText(QString::number(maxHeight));
- }else{
- ui->comboBoxLandscapeY->setCurrentText(QString::number(maxHeight));
- ui->comboBoxLandscapeX->setCurrentText("*");
- ui->comboBoxPortraitY->setCurrentText("*");
- ui->comboBoxPortraitX->setCurrentText(QString::number(maxWidth));
- ui->comboBoxSquareX->setCurrentText(QString::number(maxWidth));
- }
+void MainWindow::activate(){
+ QString theTemplate = comboText(ui->comboBoxTemplate);
+ QRegularExpression rexpr("(\\d+)x(\\d+)");
+ QRegularExpressionMatch matcher = rexpr.match(theTemplate);
+ if (matcher.hasMatch()){
+ int width = atoi(matcher.captured(1).toLatin1());
+ int height = atoi(matcher.captured(2).toLatin1());
+ setMaxDimensions(width, height);
+ }
}
/**
- * Selects the destination directory with a dialog.
+ * Clears the table.
*/
-void MainWindow::selectDestination(){
- QString dir = QFileDialog::getExistingDirectory(this,
- tr("Select Destination Directory"), ui->comboBoxTarget->currentText(),
- QFileDialog::ShowDirsOnly);
- if (!dir.isEmpty())
- ui->comboBoxTarget->setCurrentText(dir);
+void MainWindow::clear()
+{
+ ui->listWidget->clear();
}
/**
- * Selects the destination directory with a dialog.
+ * Actions while closing the application.
*/
-void MainWindow::selectSource(){
- QString dir = QFileDialog::getExistingDirectory(this,
- tr("Select Source Directory"), ui->comboBoxSourceDir->currentText(),
- QFileDialog::ShowDirsOnly);
- if (!dir.isEmpty())
- ui->comboBoxSourceDir->setCurrentText(dir);
+void MainWindow::closing(){
+ saveState();
}
/**
- * Starts the about dialog.
+ * Issues an error message.
+ *
+ * @param message the message to issue
+ * @return <code>false</code>
*/
-void MainWindow::about(){
- AboutDialog dialog(VERSION);
- dialog.exec();
+bool MainWindow::error(const QString& message){
+ log("+++ " + message);
+ return false;
}
/**
if (!m_homeDir.endsWith("/"))
m_homeDir += "/";
m_storageFile = m_homeDir + "state.conf";
- restoreState();
+}
+
+
+/**
+ * @brief Logs a message
+ *
+ * @param message the message to log
+ * @return <code>true</code>
+ */
+bool MainWindow::log(const QString& message){
+ ui->listWidget->addItem(message);
+ ui->listWidget->setCurrentRow(ui->listWidget->count() - 1);
+ return true;
+}
+
+/**
+ * @brief Logs a message
+ *
+ * Note: used by non main threads
+ *
+ * @param message the message to log
+ * @return <code>true</code>
+ */
+bool MainWindow::logAppendLast(const QString& message){
+ m_guiQueue.pushBack(ReGuiQueueItem(ReGuiQueueItem::ListEnd, ui->listWidget, message));
+ QListWidgetItem* item = ui->listWidget->item(0);
+ item->setText(item->text() + " " + message);
+ return true;
}
/**
*/
void MainWindow::on_pushButtonStop_clicked(){
m_converter->stop();
- ui->pushButtonConvert->show();
- ui->pushButtonStop->hide();
}
/**
int portraitX = comboInt(ui->comboBoxPortraitX, 0, "*", 0);
int portraitY = comboInt(ui->comboBoxPortraitY, 0, "*", 0);
int squareX = comboInt(ui->comboBoxSquareX, 0);
- int quality = comboInt(ui->comboBoxQuality, 70);
+ int quality = comboInt(ui->comboBoxQuality, 75);
+ int maxWidth = comboInt(ui->comboBoxMaxWidth, 0);
+ int maxHeight = comboInt(ui->comboBoxMaxHeight, 0);
+ QRegularExpressionMatch match = QRegularExpression("\\dx\\d").match(
+ ui->comboBoxTemplate->currentText());
+ bool simpleConversion = match.hasMatch();
if (m_errors == 0){
m_converter = new Converter(ui->comboBoxSourceDir->currentText(),
ui->comboBoxLandscapeX->currentText(),
ui->comboBoxSourcePattern->currentText(),
- ui->comboBoxDestType->currentText(), landscapeX, landscapeY, portraitX,
+ ui->comboBoxDestType->currentText(),
+ simpleConversion, maxWidth, maxHeight,
+ landscapeX, landscapeY, portraitX,
portraitY, squareX, quality, this);
// start the thread:
m_converter->start();
switch (state) {
case Converter::STATE_READY:
m_guiQueue.pushBack(ReGuiQueueItem(ReGuiQueueItem::ReadyMessage, NULL, info));
- ui->pushButtonStop->hide();
//ui->statusBar->showMessage(info);
break;
case Converter::STATE_SUB_TASK_STOPPED:
break;
}
}
-
-/**
- * @brief Logs a message
- *
- * @param message the message to log
- * @return <code>true</code>
- */
-bool MainWindow::log(const QString& message){
- ui->listWidget->insertItem(0, message);
- return true;
-}
-
-/**
- * @brief Logs a message
- *
- * Note: used by non main threads
- *
- * @param message the message to log
- * @return <code>true</code>
- */
-bool MainWindow::logAppendLast(const QString& message){
- m_guiQueue.pushBack(ReGuiQueueItem(ReGuiQueueItem::ListEnd, ui->listWidget, message));
- QListWidgetItem* item = ui->listWidget->item(0);
- item->setText(item->text() + " " + message);
- return true;
-}
-
/**
* Reads the history of the widget values and other parameters and set it.
*/
void MainWindow::restoreState(){
+ log(tr("Reading data from ") + m_storageFile);
ReStateStorage storage(m_storageFile, &m_logger);
storage.setForm("main");
storage.restore(ui->comboBoxMaxHeight, "comboBoxMaxHeight", true);
storage.restore(ui->comboBoxQuality, "comboBoxQuality", true);
storage.restore(ui->comboBoxSourceDir, "comboBoxSourceDir", true);
storage.restore(ui->comboBoxSquareX, "comboBoxSquareX", true);
- storage.restore(ui->comboBoxTarget, "comboBoxTarget", true);
+ storage.restore(ui->comboBoxTargetDir, "comboBoxTargetDir", true);
+ storage.restore(ui->comboBoxDestType, "comboBoxDestType", true);
+ storage.restore(ui->comboBoxTemplate, "comboBoxTemplate", true);
storage.close();
}
storage.store(ui->comboBoxQuality, "comboBoxQuality");
storage.store(ui->comboBoxSourceDir, "comboBoxSourceDir");
storage.store(ui->comboBoxSquareX, "comboBoxSquareX");
- storage.store(ui->comboBoxTarget, "comboBoxTarget");
+ storage.store(ui->comboBoxTargetDir, "comboBoxTargetDir");
+ storage.store(ui->comboBoxDestType, "comboBoxDestType");
+ storage.store(ui->comboBoxTemplate, "comboBoxTemplate");
storage.close();
}
+
+/**
+ * Issues a message.
+ *
+ * @param level type of the message
+ * @param message message to issue
+ * @return <code>level == LOG_ERROR</code>
+ */
+bool MainWindow::say(ReLoggerLevel level, const QString& message)
+{
+ if (level == LOG_ERROR || level == LOG_WARNING)
+ error(message);
+ else
+ log(message);
+ return level == LOG_ERROR;
+}
+
+/**
+ * Selects the destination directory with a dialog.
+ */
+void MainWindow::selectSource(){
+ QString dir = QFileDialog::getExistingDirectory(this,
+ tr("Select Source Directory"), ui->comboBoxSourceDir->currentText(),
+ QFileDialog::ShowDirsOnly);
+ if (!dir.isEmpty())
+ ui->comboBoxSourceDir->setCurrentText(dir);
+}
+
+/**
+ * Sets the maximal dimensions (from the "simple" interface).
+ *
+ * @param maxWidth the maximal width
+ * @param maxHeight the maximal height
+ */
+void MainWindow::setMaxDimensions(int maxWidth, int maxHeight){
+ if (maxWidth > maxHeight){
+ ui->comboBoxLandscapeX->setCurrentText(QString::number(maxWidth));
+ ui->comboBoxLandscapeY->setCurrentText("*");
+ ui->comboBoxPortraitX->setCurrentText("*");
+ ui->comboBoxPortraitY->setCurrentText(QString::number(maxHeight));
+ ui->comboBoxSquareX->setCurrentText(QString::number(maxHeight));
+ }else{
+ ui->comboBoxLandscapeY->setCurrentText(QString::number(maxHeight));
+ ui->comboBoxLandscapeX->setCurrentText("*");
+ ui->comboBoxPortraitY->setCurrentText("*");
+ ui->comboBoxPortraitX->setCurrentText(QString::number(maxWidth));
+ ui->comboBoxSquareX->setCurrentText(QString::number(maxWidth));
+ }
+ ui->comboBoxMaxWidth->setCurrentText(QString::number(maxWidth));
+ ui->comboBoxMaxHeight->setCurrentText(QString::number(maxHeight));
+}
+
+/**
+ * Selects the destination directory with a dialog.
+ */
+void MainWindow::selectTarget(){
+ QString dir = QFileDialog::getExistingDirectory(this,
+ tr("Select Destination Directory"), ui->comboBoxTargetDir->currentText(),
+ QFileDialog::ShowDirsOnly);
+ if (!dir.isEmpty())
+ ui->comboBoxTargetDir->setCurrentText(dir);
+}
+
/**
* Writes a text to the status line.
*
* @param message the text to set
*/
void MainWindow::setStatusMessage(bool error, const QString& message){
+ RE_UNUSED(error);
m_statusMessage->setText(message);
}
ui->pushButtonStop->setEnabled(isStart);
}
-/**
- * Issues a message.
- *
- * @param level type of the message
- * @param message message to issue
- * @return <code>level == LOG_ERROR</code>
- */
-bool MainWindow::say(ReLoggerLevel level, const QString& message)
-{
- if (level == LOG_ERROR || level == LOG_WARNING)
- error(message);
- else
- log(message);
- return level == LOG_ERROR;
-}
-
explicit MainWindow(const QString& homeDir, QWidget *parent = 0);
~MainWindow();
+public slots:
+ void closing();
public:
- bool error(const QString& message){
- log("+++ " + message);
- return false;
- }
+ bool error(const QString& message);
bool log(const QString& message);
bool logAppendLast(const QString& message);
void on_threadStateChanged(Converter::State state, const QString& info);
void setStatusMessage(bool error, const QString& message);
- void switchRun(bool runActive);
+public:
virtual bool say(ReLoggerLevel level, const QString& message);
private:
void initializeHome();
private slots:
void activate();
void about();
+ void clear();
void guiTimerUpdate();
void on_pushButtonFileSelect_clicked();
void on_pushButtonStop_clicked();
void on_pushButtonConvert_clicked();
void on_templateChangeIndex(const QString& text);
- void selectDestination();
void selectSource();
+ void selectTarget();
private:
QString m_homeDir;
QString m_storageFile;
<string>Mini: 150x100</string>
</property>
</item>
+ <item>
+ <property name="text">
+ <string>User defined</string>
+ </property>
+ </item>
</widget>
</item>
<item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
- <widget class="QComboBox" name="comboBoxTarget">
+ <widget class="QComboBox" name="comboBoxTargetDir">
<property name="editable">
<bool>true</bool>
</property>
</size>
</property>
<property name="toolTip">
- <string>Alle Bilder aus dem Quellverzeichnis konvertieren und im Zielverzeichnis ablegen</string>
+ <string>Converts the images</string>
</property>
<property name="text">
<string>&Convert</string>
</property>
</widget>
</item>
+ <item>
+ <spacer name="horizontalSpacer">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QPushButton" name="pushButtonClear">
+ <property name="toolTip">
+ <string>Clears the list</string>
+ </property>
+ <property name="text">
+ <string>C&lear</string>
+ </property>
+ <property name="shortcut">
+ <string notr="true">Ctrl+L</string>
+ </property>
+ </widget>
+ </item>
<item>
<spacer name="horizontalSpacer_4">
<property name="orientation">
<item>
<widget class="QPushButton" name="pushButtonStop">
<property name="enabled">
- <bool>false</bool>
+ <bool>true</bool>
</property>
<property name="minimumSize">
<size>
</size>
</property>
<property name="toolTip">
- <string>Alle Bilder aus dem Quellverzeichnis konvertieren und im Zielverzeichnis ablegen</string>
+ <string>Stops the conversion</string>
</property>
<property name="text">
<string>&Stop</string>
<addaction name="actionStart"/>
<addaction name="actionStop"/>
<addaction name="separator"/>
+ <addaction name="actionClear"/>
+ <addaction name="separator"/>
<addaction name="actionSelectSource"/>
- <addaction name="actionSelectDestination"/>
+ <addaction name="actionSelectTarget"/>
<addaction name="separator"/>
- <addaction name="action_Exit"/>
<addaction name="separator"/>
+ <addaction name="action_Exit"/>
</widget>
<widget class="QMenu" name="menu_Help">
<property name="title">
<bool>false</bool>
</attribute>
<addaction name="actionSelectSource"/>
- <addaction name="actionSelectDestination"/>
+ <addaction name="actionSelectTarget"/>
<addaction name="separator"/>
<addaction name="actionAbout"/>
<addaction name="separator"/>
<string>Ctrl+O</string>
</property>
</action>
- <action name="actionSelectDestination">
+ <action name="actionSelectTarget">
<property name="icon">
<iconset resource="reimgconvert.qrc">
<normaloff>:/main/icons/folder_go.png</normaloff>:/main/icons/folder_go.png</iconset>
<string>Ctrl+Shift+A</string>
</property>
</action>
+ <action name="actionClear">
+ <property name="text">
+ <string>C&lear</string>
+ </property>
+ <property name="toolTip">
+ <string>Clears the list</string>
+ </property>
+ <property name="shortcut">
+ <string notr="true">Alt+L</string>
+ </property>
+ </action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources>