00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <KoPageLayoutDia.h>
00021 #include <KoPageLayoutSize.h>
00022 #include <KoUnit.h>
00023 #include <KoUnitWidgets.h>
00024
00025 #include <klocale.h>
00026 #include <kiconloader.h>
00027 #include <kmessagebox.h>
00028 #include <kdebug.h>
00029 #include <khbox.h>
00030
00031 #include <QLabel>
00032 #include <QRadioButton>
00033 #include <QGroupBox>
00034 #include <QButtonGroup>
00035 #include <QGroupBox>
00036 #include <QPixmap>
00037 #include <QHBoxLayout>
00038 #include <QGridLayout>
00039
00040 KoPageLayoutSize::KoPageLayoutSize(QWidget *parent, const KoPageLayout& layout, KoUnit::Unit unit,const KoColumns& columns, bool unitChooser, bool enableBorders)
00041 : QWidget(parent), m_blockSignals(false)
00042 {
00043 m_layout = layout;
00044 m_unit = unit;
00045
00046 QGridLayout *grid1 = new QGridLayout( this );
00047 grid1->setSpacing( KDialog::spacingHint() );
00048 if ( unitChooser ) {
00049
00050 QWidget* unitFrame = new QWidget( this );
00051 grid1->addWidget( unitFrame, 0, 0, Qt::AlignLeft );
00052 QHBoxLayout* unitLayout = new QHBoxLayout( unitFrame );
00053 unitLayout->setSpacing( KDialog::spacingHint() );
00054
00055
00056 QLabel *lpgUnit = new QLabel( i18n( "Unit:" ), unitFrame );
00057 unitLayout->addWidget( lpgUnit, 0, Qt::AlignRight | Qt::AlignVCenter );
00058
00059
00060 QComboBox *cpgUnit = new QComboBox( unitFrame );
00061 cpgUnit->setEditable( false );
00062 lpgUnit->setBuddy( cpgUnit );
00063 cpgUnit->addItems( KoUnit::listOfUnitName() );
00064 cpgUnit->setCurrentIndex( unit );
00065 unitLayout->addWidget( cpgUnit, 0, Qt::AlignLeft | Qt::AlignVCenter );
00066 connect( cpgUnit, SIGNAL( activated( int ) ), this, SLOT( setUnitInt( int ) ) );
00067 }
00068 else {
00069 QString str=KoUnit::unitDescription(unit);
00070
00071 QLabel *lpgUnit = new QLabel( i18n("All values are given in %1.",str), this );
00072 grid1->addWidget( lpgUnit, 0, 0, Qt::AlignLeft );
00073 }
00074
00075
00076 QGroupBox *formatFrame = new QGroupBox( i18n( "Page Size" ), this );
00077 grid1->addWidget( formatFrame, 1, 0 );
00078
00079 QGridLayout *layoutPageSize = new QGridLayout( formatFrame );
00080 layoutPageSize->setSpacing( KDialog::spacingHint() );
00081
00082
00083 QLabel *lpgFormat = new QLabel( i18n( "&Size:" ), formatFrame );
00084 layoutPageSize->addWidget( lpgFormat, 0, 0 );
00085
00086 cpgFormat = new QComboBox( formatFrame );
00087 cpgFormat->setEditable( false );
00088 cpgFormat->addItems( KoPageFormat::allFormats() );
00089 lpgFormat->setBuddy( cpgFormat );
00090 layoutPageSize->addWidget( cpgFormat, 0, 1 );
00091 connect( cpgFormat, SIGNAL( activated( int ) ), this, SLOT( formatChanged( int ) ) );
00092
00093
00094
00095
00096
00097 QLabel *lpgWidth = new QLabel( i18n( "&Width:" ), formatFrame );
00098 layoutPageSize->addWidget( lpgWidth, 1, 0 );
00099
00100
00101 epgWidth = new KoUnitDoubleSpinBox( formatFrame, "Width" );
00102 lpgWidth->setBuddy( epgWidth );
00103 if ( m_layout.format != PG_CUSTOM )
00104 epgWidth->setEnabled( false );
00105 layoutPageSize->addWidget( epgWidth, 1, 1 );
00106 connect( epgWidth, SIGNAL( valueChangedPt(double) ), this, SLOT( widthChanged(double) ) );
00107
00108
00109 QLabel *lpgHeight = new QLabel( i18n( "&Height:" ), formatFrame );
00110 layoutPageSize->addWidget( lpgHeight, 1, 2 );
00111
00112
00113 epgHeight = new KoUnitDoubleSpinBox( formatFrame, "Height" );
00114 lpgHeight->setBuddy( epgHeight );
00115 if ( m_layout.format != PG_CUSTOM )
00116 epgHeight->setEnabled( false );
00117 layoutPageSize->addWidget( epgHeight, 1, 3 );
00118 connect( epgHeight, SIGNAL( valueChangedPt(double ) ), this, SLOT( heightChanged(double) ) );
00119
00120
00121 m_orientBox = new QGroupBox( i18n( "Orientation" ), this );
00122 QGridLayout *layoutOrientation =new QGridLayout( m_orientBox );
00123
00124 grid1->addWidget( m_orientBox, 2, 0 );
00125
00126 QLabel* lbPortrait = new QLabel( m_orientBox );
00127 lbPortrait->setPixmap( QPixmap( UserIcon( "koPortrait" ) ) );
00128 lbPortrait->setMaximumWidth( lbPortrait->pixmap()->width() );
00129 layoutOrientation->addWidget( lbPortrait, 0, 0 );
00130
00131 QRadioButton *rbPortrait = new QRadioButton( i18n("&Portrait"), m_orientBox );
00132 layoutOrientation->addWidget( rbPortrait, 0, 1 );
00133
00134 QLabel* lbLandscape = new QLabel( m_orientBox );
00135 lbLandscape->setPixmap( QPixmap( UserIcon( "koLandscape" ) ) );
00136 lbLandscape->setMaximumWidth( lbLandscape->pixmap()->width() );
00137 layoutOrientation->addWidget( lbLandscape, 0, 2 );
00138
00139 QRadioButton *rbLandscape = new QRadioButton( i18n("La&ndscape"), m_orientBox );
00140 layoutOrientation->addWidget( rbLandscape, 0, 3 );
00141
00142 m_orientGroup = new QButtonGroup( m_orientBox );
00143 m_orientGroup->addButton( rbPortrait, PG_PORTRAIT );
00144 m_orientGroup->addButton( rbLandscape, PG_LANDSCAPE );
00145 connect( m_orientGroup, SIGNAL (buttonClicked (int)), this, SLOT( orientationChanged(int) ));
00146
00147
00148 QGroupBox *marginsFrame = new QGroupBox( i18n( "Margins" ), this );
00149 grid1->addWidget( marginsFrame, 3, 0 );
00150
00151 QGridLayout *marginsLayout = new QGridLayout( marginsFrame );
00152 marginsLayout->setSpacing( KDialog::spacingHint() );
00153 marginsFrame->setLayout( marginsLayout );
00154
00155
00156 ebrLeft = new KoUnitDoubleSpinBox( marginsFrame, "Left" );
00157 marginsLayout->addWidget( ebrLeft, 1, 0 );
00158 connect( ebrLeft, SIGNAL( valueChangedPt( double ) ), this, SLOT( leftChanged( double ) ) );
00159
00160
00161 ebrRight = new KoUnitDoubleSpinBox( marginsFrame, "Right" );
00162 marginsLayout->addWidget( ebrRight, 1, 2 );
00163 connect( ebrRight, SIGNAL( valueChangedPt( double ) ), this, SLOT( rightChanged( double ) ) );
00164
00165
00166 ebrTop = new KoUnitDoubleSpinBox( marginsFrame, "Top" );
00167 marginsLayout->addWidget( ebrTop, 0, 1 , Qt::AlignCenter );
00168 connect( ebrTop, SIGNAL( valueChangedPt( double ) ), this, SLOT( topChanged( double ) ) );
00169
00170
00171 ebrBottom = new KoUnitDoubleSpinBox( marginsFrame, "Bottom" );
00172 marginsLayout->addWidget( ebrBottom, 2, 1, Qt::AlignCenter );
00173 connect( ebrBottom, SIGNAL( valueChangedPt( double ) ), this, SLOT( bottomChanged( double ) ) );
00174
00175
00176 pgPreview = new KoPagePreview( this, "Preview", m_layout );
00177 grid1->addWidget( pgPreview, 1, 1, 3, 2 );
00178
00179
00180 QWidget* spacer1 = new QWidget( this );
00181 QWidget* spacer2 = new QWidget( this );
00182 spacer1->setSizePolicy( QSizePolicy( QSizePolicy::Expanding,
00183 QSizePolicy::Expanding ) );
00184 spacer2->setSizePolicy( QSizePolicy( QSizePolicy::Expanding,
00185 QSizePolicy::Expanding ) );
00186 grid1->addWidget( spacer1, 4, 0 );
00187 grid1->addWidget( spacer2, 4, 1 );
00188
00189 setValues();
00190 updatePreview();
00191 pgPreview->setPageColumns( columns );
00192 setEnableBorders(enableBorders);
00193 }
00194
00195 void KoPageLayoutSize::setEnableBorders(bool on) {
00196 m_haveBorders = on;
00197 ebrLeft->setEnabled( on );
00198 ebrRight->setEnabled( on );
00199 ebrTop->setEnabled( on );
00200 ebrBottom->setEnabled( on );
00201
00202
00203 m_layout.ptLeft = on?ebrLeft->value():0;
00204 m_layout.ptRight = on?ebrRight->value():0;
00205 m_layout.ptTop = on?ebrTop->value():0;
00206 m_layout.ptBottom = on?ebrBottom->value():0;
00207
00208
00209 updatePreview();
00210 emit propertyChange(m_layout);
00211 }
00212
00213 void KoPageLayoutSize::updatePreview() {
00214 pgPreview->setPageLayout( m_layout );
00215 }
00216
00217 void KoPageLayoutSize::setValues() {
00218
00219 cpgFormat->setCurrentIndex( m_layout.format );
00220
00221 m_orientGroup->button( m_layout.orientation )->setChecked( true );
00222
00223 setUnit( m_unit );
00224 updatePreview();
00225 }
00226
00227 void KoPageLayoutSize::setUnit( KoUnit::Unit unit ) {
00228 m_unit = unit;
00229 m_blockSignals = true;
00230
00231 epgWidth->setUnit( m_unit );
00232 epgWidth->setMinMaxStep( 0, KoUnit::fromUserValue( 9999, m_unit ), KoUnit::fromUserValue( 0.01, m_unit ) );
00233 epgWidth->changeValue( m_layout.ptWidth );
00234
00235 epgHeight->setUnit( m_unit );
00236 epgHeight->setMinMaxStep( 0, KoUnit::fromUserValue( 9999, m_unit ), KoUnit::fromUserValue( 0.01, m_unit ) );
00237 epgHeight->changeValue( m_layout.ptHeight );
00238
00239 double dStep = KoUnit::fromUserValue( 0.2, m_unit );
00240
00241 ebrLeft->setUnit( m_unit );
00242 ebrLeft->changeValue( m_layout.ptLeft );
00243 ebrLeft->setMinMaxStep( 0, m_layout.ptWidth, dStep );
00244
00245 ebrRight->setUnit( m_unit );
00246 ebrRight->changeValue( m_layout.ptRight );
00247 ebrRight->setMinMaxStep( 0, m_layout.ptWidth, dStep );
00248
00249 ebrTop->setUnit( m_unit );
00250 ebrTop->changeValue( m_layout.ptTop );
00251 ebrTop->setMinMaxStep( 0, m_layout.ptHeight, dStep );
00252
00253 ebrBottom->setUnit( m_unit );
00254 ebrBottom->changeValue( m_layout.ptBottom );
00255 ebrBottom->setMinMaxStep( 0, m_layout.ptHeight, dStep );
00256
00257 m_blockSignals = false;
00258 }
00259
00260 void KoPageLayoutSize::setUnitInt( int unit ) {
00261 setUnit((KoUnit::Unit)unit);
00262 }
00263
00264 void KoPageLayoutSize::formatChanged( int format ) {
00265 if ( ( KoFormat )format == m_layout.format )
00266 return;
00267 m_layout.format = ( KoFormat )format;
00268 bool enable = (KoFormat) format == PG_CUSTOM;
00269 epgWidth->setEnabled( enable );
00270 epgHeight->setEnabled( enable );
00271
00272 if ( m_layout.format != PG_CUSTOM ) {
00273 m_layout.ptWidth = MM_TO_POINT( KoPageFormat::width(
00274 m_layout.format, m_layout.orientation ) );
00275 m_layout.ptHeight = MM_TO_POINT( KoPageFormat::height(
00276 m_layout.format, m_layout.orientation ) );
00277 }
00278
00279 epgWidth->changeValue( m_layout.ptWidth );
00280 epgHeight->changeValue( m_layout.ptHeight );
00281
00282 updatePreview( );
00283 emit propertyChange(m_layout);
00284 }
00285
00286 void KoPageLayoutSize::orientationChanged(int which) {
00287 m_layout.orientation = which == PG_PORTRAIT ? PG_PORTRAIT : PG_LANDSCAPE;
00288
00289
00290 double val = epgWidth->value();
00291 epgWidth->changeValue(epgHeight->value());
00292 epgHeight->changeValue(val);
00293
00294 m_blockSignals = true;
00295 val = ebrTop->value();
00296 if(m_layout.orientation == PG_PORTRAIT) {
00297 ebrTop->changeValue(ebrRight->value());
00298 ebrRight->changeValue(ebrBottom->value());
00299 ebrBottom->changeValue(ebrLeft->value());
00300 ebrLeft->changeValue(val);
00301 } else {
00302 ebrTop->changeValue(ebrLeft->value());
00303 ebrLeft->changeValue(ebrBottom->value());
00304 ebrBottom->changeValue(ebrRight->value());
00305 ebrRight->changeValue(val);
00306 }
00307 m_blockSignals = false;
00308
00309 setEnableBorders(m_haveBorders);
00310 }
00311
00312 void KoPageLayoutSize::widthChanged(double width) {
00313 if(m_blockSignals) return;
00314 m_layout.ptWidth = width;
00315 updatePreview();
00316 emit propertyChange(m_layout);
00317 }
00318 void KoPageLayoutSize::heightChanged(double height) {
00319 if(m_blockSignals) return;
00320 m_layout.ptHeight = height;
00321 updatePreview( );
00322 emit propertyChange(m_layout);
00323 }
00324 void KoPageLayoutSize::leftChanged( double left ) {
00325 if(m_blockSignals) return;
00326 m_layout.ptLeft = left;
00327 updatePreview();
00328 emit propertyChange(m_layout);
00329 }
00330 void KoPageLayoutSize::rightChanged(double right) {
00331 if(m_blockSignals) return;
00332 m_layout.ptRight = right;
00333 updatePreview();
00334 emit propertyChange(m_layout);
00335 }
00336 void KoPageLayoutSize::topChanged(double top) {
00337 if(m_blockSignals) return;
00338 m_layout.ptTop = top;
00339 updatePreview();
00340 emit propertyChange(m_layout);
00341 }
00342 void KoPageLayoutSize::bottomChanged(double bottom) {
00343 if(m_blockSignals) return;
00344 m_layout.ptBottom = bottom;
00345 updatePreview();
00346 emit propertyChange(m_layout);
00347 }
00348
00349 bool KoPageLayoutSize::queryClose() {
00350 if ( m_layout.ptLeft + m_layout.ptRight > m_layout.ptWidth ) {
00351 KMessageBox::error( this,
00352 i18n("The page width is smaller than the left and right margins."),
00353 i18n("Page Layout Problem") );
00354 return false;
00355 }
00356 if ( m_layout.ptTop + m_layout.ptBottom > m_layout.ptHeight ) {
00357 KMessageBox::error( this,
00358 i18n("The page height is smaller than the top and bottom margins."),
00359 i18n("Page Layout Problem") );
00360 return false;
00361 }
00362 return true;
00363 }
00364
00365 void KoPageLayoutSize::setColumns(KoColumns &columns) {
00366 pgPreview->setPageColumns(columns);
00367 }
00368
00369 #include <KoPageLayoutSize.moc>
00370 #include <kvbox.h>