kviewshell
pageSizeWidget.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include <config.h>
00011
00012 #include <kcombobox.h>
00013 #include <kdebug.h>
00014 #include <klocale.h>
00015 #include <qlineedit.h>
00016 #include <qvalidator.h>
00017
00018 #include "pageSize.h"
00019 #include "pageSizeWidget.h"
00020 #include "sizePreview.h"
00021
00022
00023
00024
00025
00026 pageSizeWidget::pageSizeWidget( QWidget* parent, const char* name, WFlags fl )
00027 : pageSizeWidget_base( parent, name, fl )
00028 {
00029 connect(&chosenSize, SIGNAL(sizeChanged(const SimplePageSize&)), previewer, SLOT(setSize(const SimplePageSize&)));
00030
00031
00032 formatChoice->insertItem(i18n("Custom Size"));
00033 formatChoice->insertStringList(chosenSize.pageSizeNames());
00034
00035
00036 if (chosenSize.formatName().isNull()) {
00037 orientationChoice->setEnabled(false);
00038 formatChoice->setCurrentItem(0);
00039 } else {
00040 orientationChoice->setEnabled(true);
00041 formatChoice->setCurrentText(chosenSize.formatName());
00042 }
00043 paperSize(formatChoice->currentItem());
00044
00045 connect(formatChoice, SIGNAL(activated(int)), this, SLOT(paperSize(int)));
00046 connect(orientationChoice, SIGNAL(activated(int)), this, SLOT(orientationChanged(int)));
00047
00048
00049
00050 connect(widthUnits, SIGNAL(activated(int)), this, SLOT(unitsChanged(int)));
00051 connect(heightUnits, SIGNAL(activated(int)), this, SLOT(unitsChanged(int)));
00052
00053
00054 connect(widthInput, SIGNAL(textChanged(const QString &)), this, SLOT(input(const QString &)));
00055 connect(heightInput, SIGNAL(textChanged(const QString &)), this, SLOT(input(const QString &)));
00056
00057
00058
00059
00060 widthInput->setValidator(new QDoubleValidator(0.0, 1200.0, 1, this, "widthValidator"));
00061 heightInput->setValidator(new QDoubleValidator(0.0, 1200.0, 1, this, "heightValidator"));
00062 }
00063
00064
00065
00066
00067 void pageSizeWidget::paperSize(int index)
00068 {
00069 widthInput->setEnabled(index == 0);
00070 heightInput->setEnabled(index == 0);
00071 orientationChoice->setEnabled(index != 0);
00072
00073 if (index != 0) {
00074 chosenSize.setPageSize(formatChoice->currentText());
00075 chosenSize.setOrientation(orientationChoice->currentItem());
00076 }
00077 widthUnits->setCurrentText(chosenSize.preferredUnit());
00078 heightUnits->setCurrentText(chosenSize.preferredUnit());
00079
00080 fillTextFields();
00081 }
00082
00083
00084 void pageSizeWidget::setPageSize(const QString& sizeName)
00085 {
00086 chosenSize.setPageSize(sizeName);
00087
00088 int index = chosenSize.formatNumber();
00089
00090 formatChoice->setCurrentItem(index+1);
00091 widthInput->setEnabled(index == -1);
00092 heightInput->setEnabled(index == -1);
00093 orientationChoice->setEnabled(index != -1);
00094
00095 widthUnits->setCurrentText(chosenSize.preferredUnit());
00096 heightUnits->setCurrentText(chosenSize.preferredUnit());
00097
00098 fillTextFields();
00099 }
00100
00101
00102 void pageSizeWidget::fillTextFields()
00103 {
00104
00105
00106
00107
00108 QString width = chosenSize.widthString(widthUnits->currentText());
00109 QString height = chosenSize.heightString(heightUnits->currentText());
00110
00111 widthInput->setText(width);
00112 heightInput->setText(height);
00113 }
00114
00115
00116 void pageSizeWidget::unitsChanged(int)
00117 {
00118
00119
00120 if (formatChoice->currentItem() != 0)
00121 fillTextFields();
00122 else
00123 input(QString::null);
00124 }
00125
00126
00127 void pageSizeWidget::setOrientation(int ori)
00128 {
00129 orientationChoice->setCurrentItem(ori);
00130 orientationChanged();
00131 }
00132
00133
00134 void pageSizeWidget::orientationChanged(int orient)
00135 {
00136
00137 chosenSize.setOrientation(orient);
00138 }
00139
00140
00141 void pageSizeWidget::input(const QString &)
00142 {
00143 chosenSize.setPageSize(widthInput->text(), widthUnits->currentText(), heightInput->text(), heightUnits->currentText());
00144 }
00145
00146
00147
00148 #include "pageSizeWidget.moc"