"Fossies" - the Fresh Open Source Software Archive

Member "src/wizardcontroller.cpp" (28 Sep 2008, 12122 Bytes) of package /windows/misc/PosteRazor-1.9.5-Source.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "wizardcontroller.cpp" see the Fossies "Dox" file reference documentation.

    1 /*
    2     PosteRazor - Make your own poster!
    3     Copyright (C) 2005-2008 by Alessandro Portale
    4     http://posterazor.sourceforge.net/
    5 
    6     This file is part of PosteRazor
    7 
    8     PosteRazor is free software; you can redistribute it and/or modify
    9     it under the terms of the GNU General Public License as published by
   10     the Free Software Foundation, either version 3 of the License, or
   11     (at your option) any later version.
   12 
   13     PosteRazor is distributed in the hope that it will be useful,
   14     but WITHOUT ANY WARRANTY; without even the implied warranty of
   15     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   16     GNU General Public License for more details.
   17 
   18     You should have received a copy of the GNU General Public License
   19     along with PosteRazor; if not, write to the Free Software
   20     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
   21 */
   22 
   23 #include "wizardcontroller.h"
   24 #include "types.h"
   25 #include <QCoreApplication>
   26 #include <QMetaObject>
   27 #include <QMetaEnum>
   28 
   29 static const QMetaEnum wizardStepsEnum()
   30 {
   31     static QMetaEnum result = WizardController::staticMetaObject.enumerator(WizardController::staticMetaObject.indexOfEnumerator("WizardSteps"));
   32     return result;
   33 }
   34 
   35 static int wizardStepsCount()
   36 {
   37     return wizardStepsEnum().keyCount();
   38 }
   39 
   40 WizardController::WizardController(QObject *wizardDialog, QObject *parent)
   41     : QObject(parent)
   42     , m_wizardStep(WizardStepInputImage)
   43     , m_imageWasLoaded(false)
   44 {
   45     connect(this, SIGNAL(wizardStepChanged(int)), wizardDialog, SLOT(setWizardStep(int)));
   46     connect(this, SIGNAL(wizardStepDescriptionChanged(const QString&, const QString&)), wizardDialog, SLOT(setWizardStepDescription(const QString&, const QString&)));
   47     connect(this, SIGNAL(prevButtonEnabled(bool)), wizardDialog, SLOT(setPrevButtonEnabled(bool)));
   48     connect(this, SIGNAL(nextButtonEnabled(bool)), wizardDialog, SLOT(setNextButtonEnabled(bool)));
   49     connect(this, SIGNAL(previewStateChanged(const QString&)), wizardDialog, SLOT(setPreviewState(const QString&)));
   50     connect(this, SIGNAL(showManualSignal(const QString&, const QString&)), wizardDialog, SLOT(showManual(const QString&, const QString&)));
   51     connect(this, SIGNAL(showWizardStepHelpSignal(const QString&, const QString&)), wizardDialog, SLOT(showWizardStepHelp(const QString&, const QString&)));
   52     connect(wizardDialog, SIGNAL(imageLoaded()), SLOT(handleImageLoaded()));
   53     connect(wizardDialog, SIGNAL(prevButtonPressed()), SLOT(handlePrevButtonPressed()));
   54     connect(wizardDialog, SIGNAL(nextButtonPressed()), SLOT(handleNextButtonPressed()));
   55     connect(wizardDialog, SIGNAL(manualSignal()), SLOT(showManual()));
   56     connect(wizardDialog, SIGNAL(wizardStepHelpSignal()), SLOT(showHelpForCurrentStep()));
   57 
   58     updateDialogWizardStep();
   59 }
   60 
   61 void WizardController::handleImageLoaded()
   62 {
   63     m_imageWasLoaded = true;
   64     updateDialogWizardStep();
   65 }
   66 
   67 void WizardController::showManual()
   68 {
   69     const QString title = Types::cleanString(QCoreApplication::translate("Help", "&Manual"));
   70     QString manual = QString(QLatin1String("<h1>%1</h1>")).arg(title);
   71     manual.append(Types::newlineToParagraph(QCoreApplication::translate("Help",
   72         "PosteRazor has its user interface organized in a 'Wizard' fashion. All settings for the poster creation can be done in %1 steps.\n"
   73         "The <b>%2</b> and <b>%3</b> buttons navigate through these steps. The <b>?</b> button opens a help window with an explanation of the current step.\n"
   74         "All entries and choices are remembered until the next usage of the PosteRazor.",
   75         "Manual preface. Place holders: %1 = Number of wizard steps, %2 = 'Back', %3 = 'Next' (will be automatically inserted)")
   76         .arg(wizardStepsCount())
   77         .arg(QCoreApplication::translate("Main window", "Back"))
   78         .arg(QCoreApplication::translate("Main window", "Next"))));
   79     for (int i = 0; i < wizardStepsEnum().keyCount(); i++) {
   80         const WizardSteps step = (WizardSteps)wizardStepsEnum().value(i);
   81         manual.append(QString(QLatin1String("<h2>%1</h2>")).arg(stepTitle(step)));
   82         manual.append(stepHelp(step));
   83     }
   84 
   85     emit showManualSignal(title, manual);
   86 }
   87 
   88 void WizardController::showHelpForCurrentStep()
   89 {
   90     QString helpText = QString("<h2>%1</h2>").arg(stepTitle(m_wizardStep)) + stepHelp(m_wizardStep);
   91     emit showWizardStepHelpSignal(Types::cleanString(stepXofYString(m_wizardStep)), helpText);
   92 }
   93 
   94 void WizardController::handlePrevButtonPressed()
   95 {
   96     m_wizardStep =
   97         m_wizardStep == WizardStepSavePoster?WizardStepPosterSize
   98         :m_wizardStep == WizardStepPosterSize?WizardStepOverlapping
   99         :m_wizardStep == WizardStepOverlapping?WizardStepPaperSize
  100         :/* m_wizardStep == WizardStepPaperSize? */WizardStepInputImage;
  101 
  102     updateDialogWizardStep();
  103 }
  104 
  105 void WizardController::handleNextButtonPressed()
  106 {
  107     m_wizardStep =
  108         m_wizardStep == WizardStepInputImage?WizardStepPaperSize
  109         :m_wizardStep == WizardStepPaperSize?WizardStepOverlapping
  110         :m_wizardStep == WizardStepOverlapping?WizardStepPosterSize
  111         :/* m_wizardStep == WizardStepPosterSize? */WizardStepSavePoster;
  112 
  113     updateDialogWizardStep();
  114 }
  115 
  116 void WizardController::updateDialogWizardStep()
  117 {
  118     emit wizardStepChanged(m_wizardStep);
  119     emit previewStateChanged(
  120         m_wizardStep == WizardStepInputImage?QLatin1String("image")
  121         :m_wizardStep == WizardStepOverlapping?QLatin1String("overlapping")
  122         :m_wizardStep == WizardStepPaperSize?QLatin1String("paper")
  123         :m_wizardStep == WizardStepPosterSize?QLatin1String("poster")
  124         :QLatin1String("poster")
  125     );
  126     emit prevButtonEnabled(m_wizardStep != WizardStepInputImage);
  127     emit nextButtonEnabled(
  128         m_wizardStep != WizardStepSavePoster
  129         && m_imageWasLoaded
  130     );
  131     updateDialogWizardStepDescription();
  132 }
  133 
  134 void WizardController::updateDialogWizardStepDescription()
  135 {
  136     emit wizardStepDescriptionChanged(stepXofYString(m_wizardStep), stepTitle(m_wizardStep));
  137 }
  138 
  139 QString WizardController::stepXofYString(WizardSteps step)
  140 {
  141     return QCoreApplication::translate("Help", "Step %1 of %2:").arg((int)step + 1).arg(wizardStepsCount());
  142 }
  143 
  144 QString WizardController::stepTitle(WizardSteps step)
  145 {
  146     QString title;
  147     title.append(
  148         step == WizardStepInputImage?  QCoreApplication::translate("Help", "Load an input image")
  149         :step == WizardStepPaperSize?  QCoreApplication::translate("Help", "Printer paper format")
  150         :step == WizardStepOverlapping?QCoreApplication::translate("Help", "Image tile overlapping")
  151         :step == WizardStepPosterSize? QCoreApplication::translate("Help", "Final poster size")
  152         :                              QCoreApplication::translate("Help", "Save the Poster"));
  153     return title;
  154 }
  155 
  156 QString WizardController::stepHelp(WizardSteps step)
  157 {
  158     QString result;
  159     switch (step) {
  160     case WizardStepInputImage:
  161         result = QCoreApplication::translate("Help",
  162             "Load an image by clicking the button with the open icon and selecting an image file, or by drag & dropping an image file on the PosteRazor. The drag & drop also works during the other steps.\n"
  163             "After loading the image, the most important informations are listed in the <b>%1</b> fields.",
  164             "Wizard step 1. Place holders: %1 = 'Image informations' (will be automatically inserted)")
  165             .arg(Types::cleanString(QCoreApplication::translate("Main window", "Image Informations")));
  166         break;
  167     case WizardStepPaperSize:
  168         result = QCoreApplication::translate("Help",
  169             "Define the paper sheet size that you use in your printer.\n"
  170             "A standard paper sheet size can be selected from the <b>%1</b> chooser, along with the desired paper sheet orientation.\n"
  171             "Alternatively, a custom paper sheet size can be defined in the <b>%2</b> tab.\n"
  172             "Paper borders are defined in the <b>%3</b> fields. Even if your printer does need no (or small) paper borders, some border might be needed to have enough area for gluing the final poster tiles together.",
  173             "Wizard step 2. Place holders: %1 = 'Format:', %2 = 'Custom', %3 = 'Borders' (will be automatically inserted)")
  174             .arg(Types::cleanString(QCoreApplication::translate("Main window", "Format:")))
  175             .arg(Types::cleanString(QCoreApplication::translate("Main window", "Custom")))
  176             .arg(Types::cleanString(QCoreApplication::translate("Main window", "Borders")));
  177         break;
  178     case WizardStepOverlapping:
  179         result = QCoreApplication::translate("Help",
  180             "Image tile overlapping is needed to have some tolerance for cutting off the unneeded borders from one side. Additionally, like the borders from the previous step, it gives more area for gluing together the final poster tiles.\n"
  181             "The <b>%1</b> defines the borders that are intended to be overlapped by the neighbor tiles. The borders on the opposite sides are intended to be cut (except on the outermost tiles).",
  182             "Wizard step 3. Place holders: %1 = 'Overlapping position' (will be automatically inserted)")
  183             .arg(Types::cleanString(QCoreApplication::translate("Main window", "Overlapping position")));
  184         break;
  185     case WizardStepPosterSize:
  186     {
  187         const QString definitionTemplate(QLatin1String("<dt><b>%1</b></dt><dd>%2</dd>"));
  188         result = QCoreApplication::translate("Help",
  189             "Define the final poster size, in one of the following three modes which can be selected by the corresponding radio buttons:",
  190             "Wizard step 4. Start of the description.");
  191         result.append("<dl>");
  192         result.append(definitionTemplate
  193             .arg(Types::cleanString(QCoreApplication::translate("Main window", "Absolute size:")))
  194             .arg(QCoreApplication::translate("Help",
  195                 "You want to have a specific size of your poster.",
  196                 "Wizard step 4. Description for 'absolute size'")));
  197         result.append(definitionTemplate
  198             .arg(Types::cleanString(QCoreApplication::translate("Main window", "Size in pages:")))
  199             .arg(QCoreApplication::translate("Help",
  200                 "You want to use whole paper sheets and specify how many of them of them you want to use.",
  201                 "Wizard step 4. Description for 'size in pages'")));
  202         result.append(definitionTemplate
  203             .arg(Types::cleanString(QCoreApplication::translate("Main window", "Size in percent:")))
  204             .arg(QCoreApplication::translate("Help",
  205                 "Your input image has a certain size which is defined by the number of pixels and dpi (dots per Inch) and your want to enlarge the image by a certain factor.",
  206                 "Wizard step 4. Description for 'size in percent'")));
  207         result.append("</dl>");
  208         result.append(QCoreApplication::translate("Help",
  209             "The aspect ratio of width and height is always 1:1 and is automatically recalculated. In the preview area, you can see the overlapping areas which are surrounded by light red rectangles.\n"
  210             "<b>%1</b> sets the alignment of the image on the total paper area of the poster. This is useful if you want to keep the unused paper.",
  211             "Wizard step 4. End of the description. Place holders: %1 = 'Image alignment' (will be automatically inserted)")
  212             .arg(Types::cleanString(QCoreApplication::translate("Main window", "Image alignment"))));
  213         break;
  214     }
  215     default:
  216         result = QCoreApplication::translate("Help",
  217             "Save the poster by clicking the save button and specifying a destination file name.\n"
  218             "Check or uncheck the <b>%1</b>, if the standard PDF handling application that is set in your operating system should be automatically started after the PDF file is saved.",
  219             "Wizard step 5. Place holders: %1 = 'Open PDF after saving' (will be automatically inserted)")
  220             .arg(Types::cleanString(QCoreApplication::translate("Main window", "Open PDF after saving")));
  221     }
  222     return Types::newlineToParagraph(result);
  223 }