00001
00002
00003
00004
00005
00006
00007 #include <QPushButton>
00008 #include <QCheckBox>
00009 #include <QLabel>
00010 #include <QSlider>
00011 #include <QToolTip>
00012 #include <QGroupBox>
00013 #include <QColorDialog>
00014 #include <QPainter>
00015
00016 #include <QList>
00017 #include <QPixmap>
00018
00019 #include "tabdisplay.h"
00020
00021 #include "scrspinbox.h"
00022 #include "prefsmanager.h"
00023 #include "units.h"
00024
00025
00026 TabDisplay::TabDisplay(QWidget* parent, const char* name)
00027 : QWidget(parent)
00028 {
00029 setupUi(this);
00030 backColor->setToolTip( "<qt>" + tr( "Color for paper" ) + "</qt>");
00031 checkUnprintable->setToolTip( "<qt>" + tr( "Mask the area outside the margins in the margin color" ) + "</qt>" );
00032 checkLink->setToolTip( "<qt>" + tr("Enable or disable the display of linked frames.") + "</qt>");
00033 checkControl->setToolTip( "<qt>" + tr("Display non-printing characters such as paragraph markers in text frames") + "</qt>");
00034 checkFrame->setToolTip( "<qt>" + tr("Turns the display of frames on or off") + "</qt>");
00035 checkLayerM->setToolTip( "<qt>" + tr("Turns the display of layer indicators on or off") + "</qt>");
00036 checkPictures->setToolTip( "<qt>" + tr("Turns the display of images on or off") + "</qt>");
00037 leftScratch->setToolTip( "<qt>" + tr( "Defines amount of space left of the document canvas available as a pasteboard for creating and modifying elements and dragging them onto the active page" ) + "</qt>" );
00038 rightScratch->setToolTip( "<qt>" + tr( "Defines amount of space right of the document canvas available as a pasteboard for creating and modifying elements and dragging them onto the active page" ) + "</qt>" );
00039 topScratch->setToolTip( "<qt>" + tr( "Defines amount of space above the document canvas available as a pasteboard for creating and modifying elements and dragging them onto the active page" ) + "</qt>" );
00040 bottomScratch->setToolTip( "<qt>" + tr( "Defines amount of space below the document canvas available as a pasteboard for creating and modifying elements and dragging them onto the active page" ) + "</qt>" );
00041 CaliText->setToolTip( "<qt>" + tr( "Set the default zoom level" ) + "</qt>");
00042 CaliGroup->setToolTip( "<qt>" + tr( "Place a ruler against your screen and drag the slider to set the zoom level so Scribus will display your pages and objects on them at the correct size" ) + "</qt>" );
00043
00044 connect(backColor, SIGNAL(clicked()), this, SLOT(changePaperColor()));
00045 connect(buttonFrameSelected, SIGNAL(clicked()), this, SLOT(changeFrameColor()));
00046 connect(buttonFrameNormal, SIGNAL(clicked()), this, SLOT(changeNormFrameColor()));
00047 connect(buttonFrameGrouped, SIGNAL(clicked()), this, SLOT(changeGroupFrameColor()));
00048 connect(buttonFrameLinked, SIGNAL(clicked()), this, SLOT(changeChainFrameColor()));
00049 connect(buttonFrameLocked, SIGNAL(clicked()), this, SLOT(changeLockFrameColor()));
00050 connect(buttonFrameAnnotation, SIGNAL(clicked()), this, SLOT(changeAnnotFrameColor()));
00051 connect(buttonSelectedPage, SIGNAL(clicked()), this, SLOT(changePageBorderColor()));
00052 connect(buttonControlChars, SIGNAL(clicked()), this, SLOT(changeControlCharsColor()));
00053
00054 connect(CaliSlider, SIGNAL(valueChanged(int)), this, SLOT(setDisScale()));
00055 connect(rulerUnitCombo, SIGNAL(activated(int)), this, SLOT(drawRuler()));
00056 }
00057
00058 void TabDisplay::restoreDefaults(struct ApplicationPrefs *prefsData, struct guidesPrefs &guidesSettings, QList<PageSet> &pageSets, int pageLayout, MarginStruct &scratch)
00059 {
00060 docUnitIndex = prefsData->docUnitIndex;
00061 double unitRatio = unitGetRatioFromIndex(docUnitIndex);
00062
00063 DisScale = prefsData->DisScale;
00064 int decimals = unitGetPrecisionFromIndex(docUnitIndex);
00065 QString unitSuffix = unitGetSuffixFromIndex(docUnitIndex);
00066 QPixmap pm(54, 14);
00067 pm.fill(prefsData->DpapColor);
00068 colorPaper = prefsData->DpapColor;
00069 backColor->setIcon(pm);
00070 backColor->setText( QString::null );
00071 pm.fill(prefsData->DFrameColor);
00072 colorFrame = prefsData->DFrameColor;
00073 buttonFrameSelected->setText( QString::null );
00074 buttonFrameSelected->setIcon(pm);
00075 pm.fill(prefsData->DFrameNormColor);
00076 colorFrameNorm = prefsData->DFrameNormColor;
00077 buttonFrameNormal->setText( QString::null );
00078 buttonFrameNormal->setIcon(pm);
00079 pm.fill(prefsData->DFrameGroupColor);
00080 colorFrameGroup = prefsData->DFrameGroupColor;
00081 buttonFrameGrouped->setText( QString::null );
00082 buttonFrameGrouped->setIcon(pm);
00083 pm.fill(prefsData->DFrameLinkColor);
00084 colorFrameLinked = prefsData->DFrameLinkColor;
00085 buttonFrameLinked->setText( QString::null );
00086 buttonFrameLinked->setIcon(pm);
00087 pm.fill(prefsData->DFrameLockColor);
00088 colorFrameLocked = prefsData->DFrameLockColor;
00089 buttonFrameLocked->setText( QString::null );
00090 buttonFrameLocked->setIcon(pm);
00091 pm.fill(prefsData->DFrameAnnotationColor);
00092 colorFrameAnnotation = prefsData->DFrameAnnotationColor;
00093 buttonFrameAnnotation->setText( QString::null );
00094 buttonFrameAnnotation->setIcon(pm);
00095 pm.fill(prefsData->DPageBorderColor);
00096 colorPageBorder = prefsData->DPageBorderColor;
00097 buttonSelectedPage->setText( QString::null );
00098 buttonSelectedPage->setIcon(pm);
00099 pm.fill(prefsData->DControlCharColor);
00100 colorControlChars = prefsData->DControlCharColor;
00101 buttonControlChars->setText( QString::null );
00102 buttonControlChars->setIcon(pm);
00103
00104 checkUnprintable->setChecked( prefsData->marginColored );
00105 checkPictures->setChecked(guidesSettings.showPic);
00106 checkLink->setChecked(guidesSettings.linkShown);
00107 checkControl->setChecked(guidesSettings.showControls);
00108 checkFrame->setChecked(guidesSettings.framesShown);
00109 checkLayerM->setChecked(guidesSettings.layerMarkersShown);
00110 checkRuler->setChecked(guidesSettings.rulerMode);
00111 checkBleed->setChecked(guidesSettings.showBleed);
00112 topScratch->setDecimals( decimals );
00113 topScratch->setMaximum(1000);
00114 topScratch->setValue(scratch.Top * unitRatio);
00115 leftScratch->setDecimals( decimals );
00116 leftScratch->setMaximum(1000);
00117 leftScratch->setValue(scratch.Left * unitRatio);
00118 bottomScratch->setDecimals( decimals );
00119 bottomScratch->setMaximum(1000);
00120 bottomScratch->setValue(scratch.Bottom * unitRatio);
00121 rightScratch->setDecimals( decimals );
00122 rightScratch->setMaximum(1000);
00123 rightScratch->setValue(scratch.Right * unitRatio);
00124 topScratch->setSuffix(unitSuffix);
00125 bottomScratch->setSuffix(unitSuffix);
00126 leftScratch->setSuffix(unitSuffix);
00127 rightScratch->setSuffix(unitSuffix);
00128 gapHorizontal->setSuffix( unitSuffix );
00129 gapHorizontal->setDecimals( decimals );
00130 gapHorizontal->setMaximum(1000);
00131 gapVertical->setSuffix( unitSuffix );
00132 gapVertical->setDecimals( decimals );
00133 gapVertical->setMaximum(1000);
00134 CaliSlider->setValue(qRound(100 * DisScale) - 150);
00135 CaliAnz->setText(QString::number(DisScale*100, 'f', 2)+" %");
00136 rulerUnitCombo->clear();
00137 rulerUnitCombo->addItems(unitGetTextUnitList());
00138 rulerUnitCombo->setCurrentIndex(docUnitIndex);
00139 drawRuler();
00140 }
00141
00142 void TabDisplay::unitChange(int docUnitIx)
00143 {
00144 docUnitIndex = docUnitIx;
00145 topScratch->setNewUnit(docUnitIndex);
00146 bottomScratch->setNewUnit(docUnitIndex);
00147 leftScratch->setNewUnit(docUnitIndex);
00148 rightScratch->setNewUnit(docUnitIndex);
00149 gapVertical->setNewUnit(docUnitIndex);
00150 gapHorizontal->setNewUnit(docUnitIndex);
00151 drawRuler();
00152 }
00153
00154 void TabDisplay::changePaperColor()
00155 {
00156 QColor neu = QColor();
00157 neu = QColorDialog::getColor(colorPaper, this);
00158 if (neu.isValid())
00159 {
00160 QPixmap pm(54, 14);
00161 pm.fill(neu);
00162 colorPaper = neu;
00163 backColor->setIcon(pm);
00164 }
00165 }
00166
00167 void TabDisplay::setPaperColor(QColor neu)
00168 {
00169 if (neu.isValid())
00170 {
00171 QPixmap pm(54, 14);
00172 pm.fill(neu);
00173 colorPaper = neu;
00174 backColor->setIcon(pm);
00175 }
00176 }
00177
00178 void TabDisplay::setDisScale()
00179 {
00180 DisScale = qMax((150.0 + CaliSlider->value()) / 100.0, 0.01);
00181 drawRuler();
00182 CaliAnz->setText(QString::number(DisScale*100, 'f', 2)+" %");
00183 }
00184
00185 void TabDisplay::drawRuler()
00186 {
00187 double xl, iter, iter2, maxi;
00188 int index = rulerUnitCombo->currentIndex();
00189 iter = unitRulerGetIter1FromIndex(index);
00190 iter2 = unitRulerGetIter2FromIndex(index);
00191 switch (index)
00192 {
00193 case 0:
00194 maxi = 200.0;
00195 break;
00196 case 1:
00197 maxi = iter2;
00198 break;
00199 case 2:
00200 maxi = 2 * iter2;
00201 break;
00202 case 3:
00203 maxi = 240.0;
00204 break;
00205 case 4:
00206 maxi = 240.0;
00207 break;
00208 default:
00209 iter = 10.0;
00210 iter2 = iter * 10.0;
00211 maxi = 200.0;
00212 break;
00213 }
00214
00215 QPixmap pm(qMin(qMax(CaliRuler->width(), qRound(maxi)+30), qRound(maxi*DisScale+30)), 21);
00216 pm.fill();
00217 QPainter p;
00218 p.begin(&pm);
00219 p.drawLine(0, 19, pm.width(), 19);
00220 p.setBrush(Qt::black);
00221 p.setPen(Qt::black);
00222 p.scale(DisScale, 1.0);
00223 for (xl = 0; xl < maxi; xl += iter)
00224 p.drawLine(QPointF(xl, 13.0), QPointF(xl, 19.0));
00225 for (xl = 0; xl < maxi+10; xl += iter2)
00226 {
00227 p.drawLine(QPointF(xl, 6.0), QPointF(xl, 19.0));
00228 p.save();
00229 p.scale(1.0 / DisScale, 1.0);
00230 switch (index)
00231 {
00232 case 2:
00233 case 4:
00234 p.drawText(static_cast<int>((xl+qRound(2/DisScale)) * DisScale), 12, QString::number(xl / iter2));
00235 break;
00236 case 3:
00237 case 5:
00238 p.drawText(static_cast<int>((xl+qRound(2/DisScale)) * DisScale), 12, QString::number(xl / iter));
00239 break;
00240 default:
00241 p.drawText(static_cast<int>((xl+qRound(2/DisScale)) * DisScale), 12, QString::number(xl / iter * 10));
00242 break;
00243 }
00244 p.restore();
00245 }
00246 p.end();
00247 CaliRuler->setPixmap(pm);
00248 }
00249
00250 void TabDisplay::setDocSetupMode()
00251 {
00252 CaliGroup->hide();
00253 selectedPageBorderLabel->hide();
00254 buttonSelectedPage->hide();
00255 groupObjFrame->hide();
00256 textColorGroup->hide();
00257 }
00258
00259 void TabDisplay::changeFrameColor()
00260 {
00261 QColor neu = QColor();
00262 neu = QColorDialog::getColor(colorFrame, this);
00263 if (neu.isValid())
00264 {
00265 QPixmap pm(54, 14);
00266 pm.fill(neu);
00267 colorFrame = neu;
00268 buttonFrameSelected->setIcon(pm);
00269 }
00270 }
00271
00272 void TabDisplay::changeNormFrameColor()
00273 {
00274 QColor neu = QColor();
00275 neu = QColorDialog::getColor(colorFrameNorm, this);
00276 if (neu.isValid())
00277 {
00278 QPixmap pm(54, 14);
00279 pm.fill(neu);
00280 colorFrameNorm = neu;
00281 buttonFrameNormal->setIcon(pm);
00282 }
00283 }
00284
00285 void TabDisplay::changeGroupFrameColor()
00286 {
00287 QColor neu = QColor();
00288 neu = QColorDialog::getColor(colorFrameGroup, this);
00289 if (neu.isValid())
00290 {
00291 QPixmap pm(54, 14);
00292 pm.fill(neu);
00293 colorFrameGroup = neu;
00294 buttonFrameGrouped->setIcon(pm);
00295 }
00296 }
00297
00298 void TabDisplay::changeChainFrameColor()
00299 {
00300 QColor neu = QColor();
00301 neu = QColorDialog::getColor(colorFrameLinked, this);
00302 if (neu.isValid())
00303 {
00304 QPixmap pm(54, 14);
00305 pm.fill(neu);
00306 colorFrameLinked = neu;
00307 buttonFrameLinked->setIcon(pm);
00308 }
00309 }
00310
00311 void TabDisplay::changeLockFrameColor()
00312 {
00313 QColor neu = QColor();
00314 neu = QColorDialog::getColor(colorFrameLocked, this);
00315 if (neu.isValid())
00316 {
00317 QPixmap pm(54, 14);
00318 pm.fill(neu);
00319 colorFrameLocked = neu;
00320 buttonFrameLocked->setIcon(pm);
00321 }
00322 }
00323
00324 void TabDisplay::changeAnnotFrameColor()
00325 {
00326 QColor neu = QColor();
00327 neu = QColorDialog::getColor(colorFrameAnnotation, this);
00328 if (neu.isValid())
00329 {
00330 QPixmap pm(54, 14);
00331 pm.fill(neu);
00332 colorFrameAnnotation = neu;
00333 buttonFrameAnnotation->setIcon(pm);
00334 }
00335 }
00336
00337 void TabDisplay::changePageBorderColor()
00338 {
00339 QColor neu = QColor();
00340 neu = QColorDialog::getColor(colorPageBorder, this);
00341 if (neu.isValid())
00342 {
00343 QPixmap pm(54, 14);
00344 pm.fill(neu);
00345 colorPageBorder = neu;
00346 buttonSelectedPage->setIcon(pm);
00347 }
00348 }
00349
00350 void TabDisplay::changeControlCharsColor()
00351 {
00352 QColor neu = QColor();
00353 neu = QColorDialog::getColor(colorControlChars, this);
00354 if (neu.isValid())
00355 {
00356 QPixmap pm(54, 14);
00357 pm.fill(neu);
00358 colorControlChars = neu;
00359 buttonControlChars->setIcon(pm);
00360 }
00361 }