00001
00002
00003
00004
00005
00006
00007 #include "CmdMediator.h"
00008 #include "DocumentSerialize.h"
00009 #include "GraphicsPoint.h"
00010 #include "GridLineLimiter.h"
00011 #include "ImportCroppingUtilBase.h"
00012 #include "Logger.h"
00013 #include "MainWindowModel.h"
00014 #include "PdfResolution.h"
00015 #include <QLocale>
00016 #include <QObject>
00017 #include <QTextStream>
00018 #include "QtToString.h"
00019 #include <QXmlStreamWriter>
00020 #include "Xml.h"
00021 #include "ZoomFactorInitial.h"
00022
00023
00024 const QLocale::NumberOption HIDE_GROUP_SEPARATOR = QLocale::OmitGroupSeparator;
00025
00026 bool DEFAULT_DRAG_DROP_EXPORT = false;
00027 bool DEFAULT_SMALL_DIALOGS = false;
00028
00029 MainWindowModel::MainWindowModel() :
00030 m_zoomControl (ZOOM_CONTROL_MENU_WHEEL_PLUSMINUS),
00031 m_zoomFactorInitial (DEFAULT_ZOOM_FACTOR_INITIAL),
00032 m_mainTitleBarFormat (MAIN_TITLE_BAR_FORMAT_PATH),
00033 m_pdfResolution (DEFAULT_IMPORT_PDF_RESOLUTION),
00034 m_importCropping (DEFAULT_IMPORT_CROPPING),
00035 m_maximumGridLines (DEFAULT_MAXIMUM_GRID_LINES),
00036 m_highlightOpacity (DEFAULT_HIGHLIGHT_OPACITY),
00037 m_smallDialogs (DEFAULT_SMALL_DIALOGS),
00038 m_dragDropExport (DEFAULT_DRAG_DROP_EXPORT)
00039 {
00040
00041 }
00042
00043 MainWindowModel::MainWindowModel(const MainWindowModel &other) :
00044 m_locale (other.locale()),
00045 m_zoomControl (other.zoomControl()),
00046 m_zoomFactorInitial (other.zoomFactorInitial()),
00047 m_mainTitleBarFormat (other.mainTitleBarFormat()),
00048 m_pdfResolution (other.pdfResolution()),
00049 m_importCropping (other.importCropping()),
00050 m_maximumGridLines (other.maximumGridLines()),
00051 m_highlightOpacity (other.highlightOpacity()),
00052 m_smallDialogs (other.smallDialogs()),
00053 m_dragDropExport (other.dragDropExport())
00054 {
00055 }
00056
00057 MainWindowModel &MainWindowModel::operator=(const MainWindowModel &other)
00058 {
00059 m_locale = other.locale();
00060 m_zoomControl = other.zoomControl();
00061 m_zoomFactorInitial = other.zoomFactorInitial();
00062 m_mainTitleBarFormat = other.mainTitleBarFormat();
00063 m_pdfResolution = other.pdfResolution();
00064 m_importCropping = other.importCropping();
00065 m_maximumGridLines = other.maximumGridLines();
00066 m_highlightOpacity = other.highlightOpacity();
00067 m_smallDialogs = other.smallDialogs();
00068 m_dragDropExport = other.dragDropExport();
00069
00070 return *this;
00071 }
00072
00073 bool MainWindowModel::dragDropExport() const
00074 {
00075 return m_dragDropExport;
00076 }
00077
00078 double MainWindowModel::highlightOpacity() const
00079 {
00080 return m_highlightOpacity;
00081 }
00082
00083 ImportCropping MainWindowModel::importCropping() const
00084 {
00085 return m_importCropping;
00086 }
00087
00088 void MainWindowModel::loadXml(QXmlStreamReader &reader)
00089 {
00090 LOG4CPP_INFO_S ((*mainCat)) << "MainWindowModel::loadXml";
00091
00092 bool success = true;
00093
00094
00095 while ((reader.tokenType() != QXmlStreamReader::EndElement) ||
00096 (reader.name() != DOCUMENT_SERIALIZE_MAIN_WINDOW)){
00097 loadNextFromReader(reader);
00098 if (reader.atEnd()) {
00099 success = false;
00100 break;
00101 }
00102 }
00103
00104 if (!success) {
00105 reader.raiseError (QObject::tr ("Cannot read main window data"));
00106 }
00107 }
00108
00109 QLocale MainWindowModel::locale () const
00110 {
00111 return m_locale;
00112 }
00113
00114 MainTitleBarFormat MainWindowModel::mainTitleBarFormat() const
00115 {
00116 return m_mainTitleBarFormat;
00117 }
00118
00119 int MainWindowModel::maximumGridLines() const
00120 {
00121 return m_maximumGridLines;
00122 }
00123
00124 int MainWindowModel::pdfResolution() const
00125 {
00126 return m_pdfResolution;
00127 }
00128
00129 void MainWindowModel::printStream(QString indentation,
00130 QTextStream &str) const
00131 {
00132 str << indentation << "MainWindowModel\n";
00133
00134 indentation += INDENTATION_DELTA;
00135
00136 str << indentation << "locale=" << m_locale.name() << "\n";
00137 str << indentation << "zoomControl=" << m_zoomControl << "\n";
00138 str << indentation << "zoomFactorInitial=" << m_zoomFactorInitial << "\n";
00139 str << indentation << "mainWindowTitleBarFormat=" << (m_mainTitleBarFormat == MAIN_TITLE_BAR_FORMAT_NO_PATH ?
00140 "NoPath" :
00141 "Path") << "\n";
00142 str << indentation << "pdfResolution=" << m_pdfResolution << "\n";
00143 str << indentation << "importCropping=" << ImportCroppingUtilBase::importCroppingToString (m_importCropping).toLatin1().data() << "\n";
00144 str << indentation << "maximumGridLines=" << m_maximumGridLines << "\n";
00145 str << indentation << "highlightOpacity=" << m_highlightOpacity << "\n";
00146 str << indentation << "smallDialogs=" << (m_smallDialogs ? "yes" : "no") << "\n";
00147 str << indentation << "dragDropExport=" << (m_dragDropExport ? "yes" : "no") << "\n";
00148 }
00149
00150 void MainWindowModel::saveXml(QXmlStreamWriter &writer) const
00151 {
00152 LOG4CPP_INFO_S ((*mainCat)) << "MainWindowModel::saveXml";
00153
00154 writer.writeStartElement(DOCUMENT_SERIALIZE_MAIN_WINDOW);
00155 writer.writeEndElement();
00156 }
00157
00158 void MainWindowModel::setDragDropExport(bool dragDropExport)
00159 {
00160 m_dragDropExport = dragDropExport;
00161 }
00162
00163 void MainWindowModel::setHighlightOpacity(double highlightOpacity)
00164 {
00165 m_highlightOpacity = highlightOpacity;
00166 }
00167
00168 void MainWindowModel::setImportCropping (ImportCropping importCropping)
00169 {
00170 m_importCropping = importCropping;
00171 }
00172
00173 void MainWindowModel::setLocale (QLocale::Language language,
00174 QLocale::Country country)
00175 {
00176 QLocale locale (language,
00177 country);
00178 locale.setNumberOptions(HIDE_GROUP_SEPARATOR);
00179
00180 m_locale = locale;
00181 }
00182
00183 void MainWindowModel::setLocale (const QLocale &locale)
00184 {
00185 m_locale = locale;
00186 m_locale.setNumberOptions(HIDE_GROUP_SEPARATOR);
00187 }
00188
00189 void MainWindowModel::setMainTitleBarFormat(MainTitleBarFormat mainTitleBarFormat)
00190 {
00191 m_mainTitleBarFormat = mainTitleBarFormat;
00192 }
00193
00194 void MainWindowModel::setMaximumGridLines(int maximumGridLines)
00195 {
00196 m_maximumGridLines = maximumGridLines;
00197 }
00198
00199 void MainWindowModel::setPdfResolution(int resolution)
00200 {
00201 m_pdfResolution = resolution;
00202 }
00203
00204 void MainWindowModel::setSmallDialogs(bool smallDialogs)
00205 {
00206 m_smallDialogs = smallDialogs;
00207 }
00208
00209 void MainWindowModel::setZoomControl (ZoomControl zoomControl)
00210 {
00211 m_zoomControl = zoomControl;
00212 }
00213
00214 void MainWindowModel::setZoomFactorInitial(ZoomFactorInitial zoomFactorInitial)
00215 {
00216 m_zoomFactorInitial = zoomFactorInitial;
00217 }
00218
00219 bool MainWindowModel::smallDialogs () const
00220 {
00221 return m_smallDialogs;
00222 }
00223
00224 ZoomControl MainWindowModel::zoomControl () const
00225 {
00226 return m_zoomControl;
00227 }
00228
00229 ZoomFactorInitial MainWindowModel::zoomFactorInitial() const
00230 {
00231 return m_zoomFactorInitial;
00232 }