• Skip to content
  • Skip to link menu
KDE 3.5 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

kviewshell

pageSizeWidget.cpp

Go to the documentation of this file.
00001 // pageSizeWidget.cpp
00002 //
00003 // Part of KVIEWSHELL - A framework for multipage text/gfx viewers
00004 //
00005 // (C) 2002-2003 Stefan Kebekus
00006 // Distributed under the GPL
00007 
00008 // Add header files alphabetically
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 // Constructs a pageSizeWidget_base which is a child of 'parent', with
00025 // the name 'name' and widget flags set to 'f'.
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   // Set up the formatChoice QComboBox
00032   formatChoice->insertItem(i18n("Custom Size"));
00033   formatChoice->insertStringList(chosenSize.pageSizeNames());
00034 
00035   // Activate the proper entry in the QComboBox
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   // Update the text fields when the user switches to a new unit, and
00049   // when the "custom format" is NOT selected.
00050   connect(widthUnits, SIGNAL(activated(int)), this, SLOT(unitsChanged(int)));
00051   connect(heightUnits, SIGNAL(activated(int)), this, SLOT(unitsChanged(int)));
00052 
00053   // Upate the chosen size whenever the user edits the input field. 
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   // Allow entries between 0 and 1200. More filtering is done by the
00058   // pageSize class, which silently ignores values which are out of
00059   // range.
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 // Receives the output from the formatChoice combobox. A value of
00066 // "zero" means that the "custom paper size" has been chosen.
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   // Warning! It is really necessary here to first generate both
00105   // strings, and then call setText() on the input widgets. Reason?
00106   // Calling setText() implicitly calls the input() method via the
00107   // textChanged()-Signal of the QLineEdit widgets.
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   // Update the text fields, i.e. show the current size in the proper
00119   // units, but only if the "custom size" is NOT selected.
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   // Update the page preview
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"

kviewshell

Skip menu "kviewshell"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

API Reference

Skip menu "API Reference"
  • kviewshell
Generated for API Reference by doxygen 1.5.9
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal