diff options
Diffstat (limited to 'kexi/3rdparty/kolibs')
21 files changed, 3595 insertions, 0 deletions
diff --git a/kexi/3rdparty/kolibs/KoPageLayoutColumns.cpp b/kexi/3rdparty/kolibs/KoPageLayoutColumns.cpp new file mode 100644 index 00000000..db5e3e25 --- /dev/null +++ b/kexi/3rdparty/kolibs/KoPageLayoutColumns.cpp @@ -0,0 +1,70 @@ +/* This file is part of the KDE project + * Copyright (C) 1998, 1999 Reginald Stadlbauer <reggie@kde.org> + * Copyright (C) 2005 Thomas Zander <zander@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; version 2. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include <KoPageLayoutColumns.h> +#include <KoPageLayoutDia.h> +#include <KoUnit.h> +#include <KoUnitWidgets.h> + +#include <qlabel.h> +#include <qlayout.h> + +KoPageLayoutColumns::KoPageLayoutColumns(QWidget *parent, const KoColumns& columns, KoUnit::Unit unit, const KoPageLayout& layout) + : KoPageLayoutColumnsBase(parent) { + m_columns = columns; + QHBoxLayout *lay = new QHBoxLayout(previewPane); + m_preview = new KoPagePreview( previewPane, "Preview", layout ); + lay->addWidget(m_preview); + lay = new QHBoxLayout(columnSpacingPane); + m_spacing = new KoUnitDoubleSpinBox( columnSpacingPane ); + m_spacing->setValue( m_columns.ptColumnSpacing ); + m_spacing->setUnit( unit ); + double dStep = KoUnit::fromUserValue( 0.2, unit ); + m_spacing->setMinMaxStep( 0, layout.ptWidth/2, dStep ); + lay->addWidget(m_spacing); + labelSpacing->setBuddy( m_spacing ); + nColumns->setValue( m_columns.columns ); + m_preview->setPageColumns( m_columns ); + + connect( nColumns, SIGNAL( valueChanged( int ) ), this, SLOT( nColChanged( int ) ) ); + connect( m_spacing, SIGNAL( valueChangedPt(double) ), this, SLOT( nSpaceChanged( double ) ) ); +} + +void KoPageLayoutColumns::setEnableColumns(bool on) { + nColumns->setEnabled(on); + m_spacing->setEnabled(on); + nColChanged(on ? nColumns->value(): 1 ); +} + +void KoPageLayoutColumns::nColChanged( int columns ) { + m_columns.columns = columns; + m_preview->setPageColumns( m_columns ); + emit propertyChange(m_columns); +} + +void KoPageLayoutColumns::nSpaceChanged( double spacing ) { + m_columns.ptColumnSpacing = spacing; + emit propertyChange(m_columns); +} + +void KoPageLayoutColumns::setLayout(KoPageLayout &layout) { + m_preview->setPageLayout( layout ); +} + +#include <KoPageLayoutColumns.moc> diff --git a/kexi/3rdparty/kolibs/KoPageLayoutColumns.h b/kexi/3rdparty/kolibs/KoPageLayoutColumns.h new file mode 100644 index 00000000..be0a4a49 --- /dev/null +++ b/kexi/3rdparty/kolibs/KoPageLayoutColumns.h @@ -0,0 +1,75 @@ +/* This file is part of the KDE project + * Copyright (C) 1998, 1999 Reginald Stadlbauer <reggie@kde.org> + * Copyright (C) 2005 Thomas Zander <zander@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; version 2. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +// Description: Page Layout Dialog (sources) + +#ifndef kopagelayoutcolumns_h +#define kopagelayoutcolumns_h + +#include <KoUnit.h> +#include <KoPageLayout.h> +#include <KoPageLayoutColumnsBase.h> + +class QWidget; +class KoUnitDoubleSpinBox; +class KoPagePreview; + +/** + * This class is a widget that shows the KoColumns data structure and allows the user to change it. + */ +class KoPageLayoutColumns : public KoPageLayoutColumnsBase { + Q_OBJECT + +public: + /** + * Contructor + * @param parent the parent widget + * @param columns the KoColumns data structure that this dialog should be initialzed with + * @param unit the unit-type (mm/cm/inch) that the dialog should show + * @param layout the page layout that the preview should be initialzed with. + */ + KoPageLayoutColumns(QWidget *parent, const KoColumns& columns, KoUnit::Unit unit, const KoPageLayout& layout); + + /** + * Update the page preview widget with the param layout. + * @param layout the new layout + */ + void setLayout(KoPageLayout &layout); +public slots: + + /** + * Enable the user to edit the columns + * @param on if true enable the user to change the columns count + */ + void setEnableColumns(bool on); + +signals: + void propertyChange(KoColumns &columns); + +protected: + KoColumns m_columns; + KoPagePreview *m_preview; + KoUnitDoubleSpinBox *m_spacing; + +private slots: + void nColChanged( int ); + void nSpaceChanged( double ); +}; + +#endif diff --git a/kexi/3rdparty/kolibs/KoPageLayoutColumnsBase.ui b/kexi/3rdparty/kolibs/KoPageLayoutColumnsBase.ui new file mode 100644 index 00000000..1ffe032d --- /dev/null +++ b/kexi/3rdparty/kolibs/KoPageLayoutColumnsBase.ui @@ -0,0 +1,99 @@ +<!DOCTYPE UI><UI version="3.3" stdsetdef="1"> +<class>KoPageLayoutColumnsBase</class> +<widget class="QWidget"> + <property name="name"> + <cstring>KoPageLayoutColumnsBase</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>361</width> + <height>169</height> + </rect> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QFrame" row="1" column="1"> + <property name="name"> + <cstring>columnSpacingPane</cstring> + </property> + <property name="frameShape"> + <enum>NoFrame</enum> + </property> + <property name="frameShadow"> + <enum>Raised</enum> + </property> + </widget> + <widget class="QLabel" row="0" column="0"> + <property name="name"> + <cstring>textLabel1</cstring> + </property> + <property name="text"> + <string>Columns:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>nColumns</cstring> + </property> + </widget> + <widget class="QLabel" row="1" column="0"> + <property name="name"> + <cstring>labelSpacing</cstring> + </property> + <property name="text"> + <string>Column spacing:</string> + </property> + </widget> + <spacer row="2" column="0" rowspan="1" colspan="2"> + <property name="name"> + <cstring>spacer1</cstring> + </property> + <property name="orientation"> + <enum>Vertical</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>20</width> + <height>20</height> + </size> + </property> + </spacer> + <widget class="QFrame" row="0" column="2" rowspan="3" colspan="1"> + <property name="name"> + <cstring>previewPane</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>7</vsizetype> + <horstretch>1</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="frameShape"> + <enum>NoFrame</enum> + </property> + <property name="frameShadow"> + <enum>Raised</enum> + </property> + </widget> + <widget class="QSpinBox" row="0" column="1"> + <property name="name"> + <cstring>nColumns</cstring> + </property> + <property name="maxValue"> + <number>16</number> + </property> + <property name="minValue"> + <number>1</number> + </property> + </widget> + </grid> +</widget> +<layoutdefaults spacing="6" margin="11"/> +</UI> diff --git a/kexi/3rdparty/kolibs/KoPageLayoutHeader.cpp b/kexi/3rdparty/kolibs/KoPageLayoutHeader.cpp new file mode 100644 index 00000000..ad5e018c --- /dev/null +++ b/kexi/3rdparty/kolibs/KoPageLayoutHeader.cpp @@ -0,0 +1,73 @@ +/* This file is part of the KDE project + * Copyright (C) 2005 Thomas Zander <zander@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; version 2. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include <KoPageLayoutHeader.h> +#include <KoPageLayoutHeader.moc> +#include <KoUnitWidgets.h> + +#include <qlayout.h> +#include <qcheckbox.h> + +KoPageLayoutHeader::KoPageLayoutHeader(QWidget *parent, KoUnit::Unit unit, const KoKWHeaderFooter &kwhf) + : KoPageLayoutHeaderBase(parent) { + m_headerFooters = kwhf; + QHBoxLayout *lay = new QHBoxLayout(headerSpacingPane); + m_headerSpacing = new KoUnitDoubleSpinBox( headerSpacingPane, 0.0, 999.0, 0.5, kwhf.ptHeaderBodySpacing, unit ); + lay->addWidget(m_headerSpacing); + + lay = new QHBoxLayout(footerSpacingPane); + m_footerSpacing = new KoUnitDoubleSpinBox( footerSpacingPane, 0.0, 999.0, 0.5, kwhf.ptFooterBodySpacing, unit ); + lay->addWidget(m_footerSpacing); + + lay = new QHBoxLayout(footnotePane); + m_footnoteSpacing = new KoUnitDoubleSpinBox( footnotePane, 0.0, 999.0, 0.5, kwhf.ptFootNoteBodySpacing, unit ); + lay->addWidget(m_footnoteSpacing); + + if ( kwhf.header == HF_FIRST_DIFF || kwhf.header == HF_FIRST_EO_DIFF ) + rhFirst->setChecked( true ); + if ( kwhf.header == HF_EO_DIFF || kwhf.header == HF_FIRST_EO_DIFF ) + rhEvenOdd->setChecked( true ); + if ( kwhf.footer == HF_FIRST_DIFF || kwhf.footer == HF_FIRST_EO_DIFF ) + rfFirst->setChecked( true ); + if ( kwhf.footer == HF_EO_DIFF || kwhf.footer == HF_FIRST_EO_DIFF ) + rfEvenOdd->setChecked( true ); +} + +const KoKWHeaderFooter& KoPageLayoutHeader::headerFooter() { + if ( rhFirst->isChecked() && rhEvenOdd->isChecked() ) + m_headerFooters.header = HF_FIRST_EO_DIFF; + else if ( rhFirst->isChecked() ) + m_headerFooters.header = HF_FIRST_DIFF; + else if ( rhEvenOdd->isChecked() ) + m_headerFooters.header = HF_EO_DIFF; + else + m_headerFooters.header = HF_SAME; + + m_headerFooters.ptHeaderBodySpacing = m_headerSpacing->value(); + m_headerFooters.ptFooterBodySpacing = m_footerSpacing->value(); + m_headerFooters.ptFootNoteBodySpacing = m_footnoteSpacing->value(); + if ( rfFirst->isChecked() && rfEvenOdd->isChecked() ) + m_headerFooters.footer = HF_FIRST_EO_DIFF; + else if ( rfFirst->isChecked() ) + m_headerFooters.footer = HF_FIRST_DIFF; + else if ( rfEvenOdd->isChecked() ) + m_headerFooters.footer = HF_EO_DIFF; + else + m_headerFooters.footer = HF_SAME; + return m_headerFooters; +} diff --git a/kexi/3rdparty/kolibs/KoPageLayoutHeader.h b/kexi/3rdparty/kolibs/KoPageLayoutHeader.h new file mode 100644 index 00000000..65449dc0 --- /dev/null +++ b/kexi/3rdparty/kolibs/KoPageLayoutHeader.h @@ -0,0 +1,44 @@ +/* This file is part of the KDE project + * Copyright (C) 2005 Thomas Zander <zander@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; version 2. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef kopagelayoutheader_h +#define kopagelayoutheader_h + +#include <KoUnit.h> +#include <KoPageLayout.h> +#include <KoPageLayoutHeaderBase.h> + +class QWidget; +class KoUnitDoubleSpinBox; +class KoPagePreview; + +class KoPageLayoutHeader : public KoPageLayoutHeaderBase { + Q_OBJECT + +public: + KoPageLayoutHeader(QWidget *parent, KoUnit::Unit unit, const KoKWHeaderFooter &kwhf); + const KoKWHeaderFooter& headerFooter(); + +private: + KoUnitDoubleSpinBox *m_headerSpacing, *m_footerSpacing, *m_footnoteSpacing; + + KoKWHeaderFooter m_headerFooters; +}; + +#endif + diff --git a/kexi/3rdparty/kolibs/KoPageLayoutHeaderBase.ui b/kexi/3rdparty/kolibs/KoPageLayoutHeaderBase.ui new file mode 100644 index 00000000..d46ca98e --- /dev/null +++ b/kexi/3rdparty/kolibs/KoPageLayoutHeaderBase.ui @@ -0,0 +1,221 @@ +<!DOCTYPE UI><UI version="3.3" stdsetdef="1"> +<class>KoPageLayoutHeaderBase</class> +<widget class="QWidget"> + <property name="name"> + <cstring>KoPageLayoutHeaderBase</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>445</width> + <height>437</height> + </rect> + </property> + <vbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QGroupBox"> + <property name="name"> + <cstring>groupBox1</cstring> + </property> + <property name="title"> + <string>Header</string> + </property> + <vbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QCheckBox"> + <property name="name"> + <cstring>rhFirst</cstring> + </property> + <property name="text"> + <string>Different header for the first page</string> + </property> + </widget> + <widget class="QCheckBox"> + <property name="name"> + <cstring>rhEvenOdd</cstring> + </property> + <property name="text"> + <string>Different header for even and odd pages</string> + </property> + </widget> + <widget class="QLayoutWidget"> + <property name="name"> + <cstring>layout1</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <spacer> + <property name="name"> + <cstring>spacer2</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>21</width> + <height>20</height> + </size> + </property> + </spacer> + <widget class="QLabel"> + <property name="name"> + <cstring>textLabel3</cstring> + </property> + <property name="text"> + <string>Spacing between header and body:</string> + </property> + </widget> + <widget class="QFrame"> + <property name="name"> + <cstring>headerSpacingPane</cstring> + </property> + <property name="frameShape"> + <enum>NoFrame</enum> + </property> + <property name="frameShadow"> + <enum>Raised</enum> + </property> + </widget> + </hbox> + </widget> + </vbox> + </widget> + <widget class="QGroupBox"> + <property name="name"> + <cstring>groupBox2</cstring> + </property> + <property name="title"> + <string>Footer</string> + </property> + <vbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QCheckBox"> + <property name="name"> + <cstring>rfFirst</cstring> + </property> + <property name="text"> + <string>Different footer for the first page</string> + </property> + </widget> + <widget class="QCheckBox"> + <property name="name"> + <cstring>rfEvenOdd</cstring> + </property> + <property name="text"> + <string>Different footer for even and odd pages</string> + </property> + </widget> + <widget class="QLayoutWidget"> + <property name="name"> + <cstring>layout2</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <spacer> + <property name="name"> + <cstring>spacer3</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>41</width> + <height>20</height> + </size> + </property> + </spacer> + <widget class="QLabel"> + <property name="name"> + <cstring>textLabel4</cstring> + </property> + <property name="text"> + <string>Spacing between footer and body:</string> + </property> + </widget> + <widget class="QFrame"> + <property name="name"> + <cstring>footerSpacingPane</cstring> + </property> + <property name="frameShape"> + <enum>NoFrame</enum> + </property> + <property name="frameShadow"> + <enum>Raised</enum> + </property> + </widget> + </hbox> + </widget> + </vbox> + </widget> + <widget class="QGroupBox"> + <property name="name"> + <cstring>groupBox3</cstring> + </property> + <property name="title"> + <string>Footnote/Endnote</string> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <spacer> + <property name="name"> + <cstring>spacer4</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + <widget class="QLabel"> + <property name="name"> + <cstring>textLabel5</cstring> + </property> + <property name="text"> + <string>Spacing between footnote and body:</string> + </property> + </widget> + <widget class="QFrame"> + <property name="name"> + <cstring>footnotePane</cstring> + </property> + <property name="frameShape"> + <enum>NoFrame</enum> + </property> + <property name="frameShadow"> + <enum>Raised</enum> + </property> + </widget> + </hbox> + </widget> + </vbox> +</widget> +<layoutdefaults spacing="6" margin="11"/> +</UI> diff --git a/kexi/3rdparty/kolibs/KoPageLayoutSize.cpp b/kexi/3rdparty/kolibs/KoPageLayoutSize.cpp new file mode 100644 index 00000000..cb22fe9c --- /dev/null +++ b/kexi/3rdparty/kolibs/KoPageLayoutSize.cpp @@ -0,0 +1,343 @@ +/* This file is part of the KDE project + * Copyright (C) 1998, 1999 Reginald Stadlbauer <reggie@kde.org> + * Copyright (C) 2005 Thomas Zander <zander@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; version 2. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include <KoPageLayoutDia.h> +#include <KoPageLayoutSize.h> +#include <KoUnit.h> +#include <KoUnitWidgets.h> + +#include <klocale.h> +#include <kiconloader.h> +#include <kmessagebox.h> + +#include <qlabel.h> +#include <qlayout.h> +#include <qradiobutton.h> +#include <qhbox.h> +#include <qvgroupbox.h> +#include <qhbuttongroup.h> + +KoPageLayoutSize::KoPageLayoutSize(QWidget *parent, const KoPageLayout& layout, KoUnit::Unit unit,const KoColumns& columns, bool unitChooser, bool enableBorders) + : QWidget(parent) { + m_layout = layout; + m_unit = unit; + + QGridLayout *grid1 = new QGridLayout( this, 5, 2, 0, KDialog::spacingHint() ); + if ( unitChooser ) { + // ------------- unit _______________ + QWidget* unitFrame = new QWidget( this ); + grid1->addWidget( unitFrame, 0, 0, Qt::AlignLeft ); + QBoxLayout* unitLayout = new QHBoxLayout( unitFrame, KDialog::marginHint(), KDialog::spacingHint() ); + + // label unit + QLabel *lpgUnit = new QLabel( i18n( "Unit:" ), unitFrame ); + unitLayout->addWidget( lpgUnit, 0, Qt::AlignRight | Qt::AlignVCenter ); + + // combo unit + cpgUnit = new QComboBox( false, unitFrame, "cpgUnit" ); + lpgUnit->setBuddy( cpgUnit ); + cpgUnit->insertStringList( KoUnit::listOfUnitName() ); + cpgUnit->setCurrentItem( unit ); + unitLayout->addWidget( cpgUnit, 0, Qt::AlignLeft | Qt::AlignVCenter ); + connect( cpgUnit, SIGNAL( activated( int ) ), this, SLOT( setUnitInt( int ) ) ); + } + else { + QString str=KoUnit::unitDescription(unit); + + QLabel *lpgUnit = new QLabel( i18n("All values are given in %1.").arg(str), this ); + grid1->addWidget( lpgUnit, 0, 0, Qt::AlignLeft ); + } + + // -------------- page size ----------------- + QVGroupBox *formatFrame = new QVGroupBox( i18n( "Page Size" ), this ); + grid1->addWidget( formatFrame, 1, 0 ); + + QHBox *formatPageSize = new QHBox( formatFrame ); + formatPageSize->setSpacing( KDialog::spacingHint() ); + + // label page size + QLabel *lpgFormat = new QLabel( i18n( "&Size:" ), formatPageSize ); + + // combo size + cpgFormat = new QComboBox( false, formatPageSize, "cpgFormat" ); + cpgFormat->insertStringList( KoPageFormat::allFormats() ); + lpgFormat->setBuddy( cpgFormat ); + connect( cpgFormat, SIGNAL( activated( int ) ), this, SLOT( formatChanged( int ) ) ); + + // spacer + formatPageSize->setStretchFactor( new QWidget( formatPageSize ), 10 ); + + QHBox *formatCustomSize = new QHBox( formatFrame ); + formatCustomSize->setSpacing( KDialog::spacingHint() ); + + // label width + QLabel *lpgWidth = new QLabel( i18n( "&Width:" ), formatCustomSize ); + + // linedit width + epgWidth = new KoUnitDoubleSpinBox( formatCustomSize, "Width" ); + lpgWidth->setBuddy( epgWidth ); + if ( m_layout.format != PG_CUSTOM ) + epgWidth->setEnabled( false ); + connect( epgWidth, SIGNAL( valueChangedPt(double) ), this, SLOT( widthChanged(double) ) ); + + // label height + QLabel *lpgHeight = new QLabel( i18n( "&Height:" ), formatCustomSize ); + + // linedit height + epgHeight = new KoUnitDoubleSpinBox( formatCustomSize, "Height" ); + lpgHeight->setBuddy( epgHeight ); + if ( m_layout.format != PG_CUSTOM ) + epgHeight->setEnabled( false ); + connect( epgHeight, SIGNAL( valueChangedPt(double ) ), this, SLOT( heightChanged(double) ) ); + + // --------------- orientation --------------- + m_orientGroup = new QHButtonGroup( i18n( "Orientation" ), this ); + m_orientGroup->setInsideSpacing( KDialog::spacingHint() ); + grid1->addWidget( m_orientGroup, 2, 0 ); + + QLabel* lbPortrait = new QLabel( m_orientGroup ); + lbPortrait->setPixmap( QPixmap( UserIcon( "koPortrait" ) ) ); + lbPortrait->setMaximumWidth( lbPortrait->pixmap()->width() ); + new QRadioButton( i18n("&Portrait"), m_orientGroup ); + + QLabel* lbLandscape = new QLabel( m_orientGroup ); + lbLandscape->setPixmap( QPixmap( UserIcon( "koLandscape" ) ) ); + lbLandscape->setMaximumWidth( lbLandscape->pixmap()->width() ); + new QRadioButton( i18n("La&ndscape"), m_orientGroup ); + + connect( m_orientGroup, SIGNAL (clicked (int)), this, SLOT( orientationChanged(int) )); + + // --------------- page margins --------------- + QVGroupBox *marginsFrame = new QVGroupBox( i18n( "Margins" ), this ); + marginsFrame->setColumnLayout( 0, Qt::Vertical ); + marginsFrame->setMargin( KDialog::marginHint() ); + grid1->addWidget( marginsFrame, 3, 0 ); + + QGridLayout *marginsLayout = new QGridLayout( marginsFrame->layout(), 3, 3, + KDialog::spacingHint() ); + + // left margin + ebrLeft = new KoUnitDoubleSpinBox( marginsFrame, "Left" ); + marginsLayout->addWidget( ebrLeft, 1, 0 ); + connect( ebrLeft, SIGNAL( valueChangedPt( double ) ), this, SLOT( leftChanged( double ) ) ); + + // right margin + ebrRight = new KoUnitDoubleSpinBox( marginsFrame, "Right" ); + marginsLayout->addWidget( ebrRight, 1, 2 ); + connect( ebrRight, SIGNAL( valueChangedPt( double ) ), this, SLOT( rightChanged( double ) ) ); + + // top margin + ebrTop = new KoUnitDoubleSpinBox( marginsFrame, "Top" ); + marginsLayout->addWidget( ebrTop, 0, 1 , Qt::AlignCenter ); + connect( ebrTop, SIGNAL( valueChangedPt( double ) ), this, SLOT( topChanged( double ) ) ); + + // bottom margin + ebrBottom = new KoUnitDoubleSpinBox( marginsFrame, "Bottom" ); + marginsLayout->addWidget( ebrBottom, 2, 1, Qt::AlignCenter ); + connect( ebrBottom, SIGNAL( valueChangedPt( double ) ), this, SLOT( bottomChanged( double ) ) ); + + // ------------- preview ----------- + pgPreview = new KoPagePreview( this, "Preview", m_layout ); + grid1->addMultiCellWidget( pgPreview, 1, 3, 1, 1 ); + + // ------------- spacers ----------- + QWidget* spacer1 = new QWidget( this ); + QWidget* spacer2 = new QWidget( this ); + spacer1->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, + QSizePolicy::Expanding ) ); + spacer2->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, + QSizePolicy::Expanding ) ); + grid1->addWidget( spacer1, 4, 0 ); + grid1->addWidget( spacer2, 4, 1 ); + + setValues(); + updatePreview(); + pgPreview->setPageColumns( columns ); + setEnableBorders(enableBorders); +} + +void KoPageLayoutSize::setEnableBorders(bool on) { + ebrLeft->setEnabled( on ); + ebrRight->setEnabled( on ); + ebrTop->setEnabled( on ); + ebrBottom->setEnabled( on ); + + // update m_layout + m_layout.ptLeft = on?ebrLeft->value():0; + m_layout.ptRight = on?ebrRight->value():0; + m_layout.ptTop = on?ebrTop->value():0; + m_layout.ptBottom = on?ebrBottom->value():0; + + // use updated m_layout + updatePreview(); + emit propertyChange(m_layout); +} + +void KoPageLayoutSize::updatePreview() { + pgPreview->setPageLayout( m_layout ); +} + +void KoPageLayoutSize::setValues() { + // page format + cpgFormat->setCurrentItem( m_layout.format ); + // orientation + m_orientGroup->setButton( m_layout.orientation == PG_PORTRAIT ? 0: 1 ); + + setUnit( m_unit ); + pgPreview->setPageLayout( m_layout ); +} + +void KoPageLayoutSize::setUnit( KoUnit::Unit unit ) { + m_unit = unit; + + //setUnit always befor changeValue + epgWidth->setUnit( m_unit ); + epgWidth->setMinMaxStep( 0, KoUnit::fromUserValue( 9999, m_unit ), KoUnit::fromUserValue( 0.01, m_unit ) ); + epgWidth->changeValue( m_layout.ptWidth ); + + epgHeight->setUnit( m_unit ); + epgHeight->setMinMaxStep( 0, KoUnit::fromUserValue( 9999, m_unit ), KoUnit::fromUserValue( 0.01, m_unit ) ); + epgHeight->changeValue( m_layout.ptHeight ); + + double dStep = KoUnit::fromUserValue( 0.2, m_unit ); + + ebrLeft->setUnit( m_unit ); + ebrLeft->changeValue( m_layout.ptLeft ); + ebrLeft->setMinMaxStep( 0, m_layout.ptWidth, dStep ); + + ebrRight->setUnit( m_unit ); + ebrRight->changeValue( m_layout.ptRight ); + ebrRight->setMinMaxStep( 0, m_layout.ptWidth, dStep ); + + ebrTop->setUnit( m_unit ); + ebrTop->changeValue( m_layout.ptTop ); + ebrTop->setMinMaxStep( 0, m_layout.ptHeight, dStep ); + + ebrBottom->setUnit( m_unit ); + ebrBottom->changeValue( m_layout.ptBottom ); + ebrBottom->setMinMaxStep( 0, m_layout.ptHeight, dStep ); + emit propertyChange(m_layout); +} + +void KoPageLayoutSize::setUnitInt( int unit ) { + setUnit((KoUnit::Unit)unit); +} + +void KoPageLayoutSize::formatChanged( int format ) { + if ( ( KoFormat )format == m_layout.format ) + return; + m_layout.format = ( KoFormat )format; + bool enable = (KoFormat) format == PG_CUSTOM; + epgWidth->setEnabled( enable ); + epgHeight->setEnabled( enable ); + + if ( m_layout.format != PG_CUSTOM ) { + m_layout.ptWidth = MM_TO_POINT( KoPageFormat::width( + m_layout.format, m_layout.orientation ) ); + m_layout.ptHeight = MM_TO_POINT( KoPageFormat::height( + m_layout.format, m_layout.orientation ) ); + } + + epgWidth->changeValue( m_layout.ptWidth ); + epgHeight->changeValue( m_layout.ptHeight ); + + updatePreview( ); + emit propertyChange(m_layout); +} + +void KoPageLayoutSize::orientationChanged(int which) { + KoOrientation oldOrientation = m_layout.orientation; + m_layout.orientation = which == 0 ? PG_PORTRAIT : PG_LANDSCAPE; + + // without this check, width & height would be swapped around (below) + // even though the orientation has not changed + if (m_layout.orientation == oldOrientation) return; + + m_layout.ptWidth = epgWidth->value(); + m_layout.ptHeight = epgHeight->value(); + m_layout.ptLeft = ebrLeft->value(); + m_layout.ptRight = ebrRight->value(); + m_layout.ptTop = ebrTop->value(); + m_layout.ptBottom = ebrBottom->value(); + + // swap dimension and adjust margins + qSwap( m_layout.ptWidth, m_layout.ptHeight ); + double tmp = m_layout.ptTop; + m_layout.ptTop = m_layout.ptRight; + m_layout.ptRight = m_layout.ptBottom; + m_layout.ptBottom = m_layout.ptLeft; + m_layout.ptLeft = tmp; + + setValues(); + updatePreview( ); + emit propertyChange(m_layout); +} + +void KoPageLayoutSize::widthChanged(double width) { + m_layout.ptWidth = width; + updatePreview(); + emit propertyChange(m_layout); +} +void KoPageLayoutSize::heightChanged(double height) { + m_layout.ptHeight = height; + updatePreview( ); + emit propertyChange(m_layout); +} +void KoPageLayoutSize::leftChanged( double left ) { + m_layout.ptLeft = left; + updatePreview(); + emit propertyChange(m_layout); +} +void KoPageLayoutSize::rightChanged(double right) { + m_layout.ptRight = right; + updatePreview(); + emit propertyChange(m_layout); +} +void KoPageLayoutSize::topChanged(double top) { + m_layout.ptTop = top; + updatePreview(); + emit propertyChange(m_layout); +} +void KoPageLayoutSize::bottomChanged(double bottom) { + m_layout.ptBottom = bottom; + updatePreview(); + emit propertyChange(m_layout); +} + +bool KoPageLayoutSize::queryClose() { + if ( m_layout.ptLeft + m_layout.ptRight > m_layout.ptWidth ) { + KMessageBox::error( this, + i18n("The page width is smaller than the left and right margins."), + i18n("Page Layout Problem") ); + return false; + } + if ( m_layout.ptTop + m_layout.ptBottom > m_layout.ptHeight ) { + KMessageBox::error( this, + i18n("The page height is smaller than the top and bottom margins."), + i18n("Page Layout Problem") ); + return false; + } + return true; +} + +void KoPageLayoutSize::setColumns(KoColumns &columns) { + pgPreview->setPageColumns(columns); +} + +#include <KoPageLayoutSize.moc> diff --git a/kexi/3rdparty/kolibs/KoPageLayoutSize.h b/kexi/3rdparty/kolibs/KoPageLayoutSize.h new file mode 100644 index 00000000..e32f9670 --- /dev/null +++ b/kexi/3rdparty/kolibs/KoPageLayoutSize.h @@ -0,0 +1,115 @@ +/* This file is part of the KDE project + * Copyright (C) 1998, 1999 Reginald Stadlbauer <reggie@kde.org> + * Copyright (C) 2005 Thomas Zander <zander@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; version 2. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef kopagelayoutsize_h +#define kopagelayoutsize_h + +#include <qgroupbox.h> +#include <KoGlobal.h> +#include <KoUnit.h> +#include <kdialogbase.h> +#include <KoPageLayout.h> +#include <KoPageLayoutDia.h> + +class QComboBox; +class KoUnitDoubleSpinBox; +class KoPageLayoutColumns; + +/** + * This class is a widget that shows the KoPageLayout data structure and allows the user to change it. + */ +class KoPageLayoutSize : public QWidget { + Q_OBJECT + +public: + /** + * Contructor + * @param parent the parent widget + * @param layout the page layout that this widget should be initialzed with. + * @param unit the unit-type (mm/cm/inch) that the dialog should show + * @param columns the KoColumns (amout of columns) that the preview should be initialized with + * @param unitChooser if true a combobox with the unit-type is shown for the user to change + * @param enableBorders if true enable the user to change the margins (aka borders) of the page + */ + KoPageLayoutSize(QWidget *parent, const KoPageLayout& layout, KoUnit::Unit unit, + const KoColumns& columns, bool unitChooser, bool enableBorders); + + /** + * @return if the dialog is in a sane state and the values can be used. + */ + bool queryClose(); + /** + * Update the page preview widget with the param columns. + * @param columns the new columns + */ + void setColumns(KoColumns &columns); + +public slots: + /** + * Set a new unit for the widget updating the widgets. + * @param unit the new unit + */ + void setUnit( KoUnit::Unit unit ); + /** + * Enable the user to edit the page border size + * @param on if true enable the user to change the margins (aka borders) of the page + */ + void setEnableBorders(bool on); + +signals: + /** + * Emitted whenever the user changed something in the dialog. + * @param layout the update layout structure with currently displayed info. + * Note that the info may not be fully correct and physically possible (in which + * case queryClose will return false) + */ + void propertyChange(KoPageLayout &layout); + +protected: + QComboBox *cpgUnit; + QComboBox *cpgFormat; + KoUnitDoubleSpinBox *epgWidth; + KoUnitDoubleSpinBox *epgHeight; + KoUnitDoubleSpinBox *ebrLeft; + KoUnitDoubleSpinBox *ebrRight; + KoUnitDoubleSpinBox *ebrTop; + KoUnitDoubleSpinBox *ebrBottom; + KoPagePreview *pgPreview; + QButtonGroup *m_orientGroup; + +protected slots: + void formatChanged( int ); + void widthChanged( double ); + void heightChanged( double ); + void leftChanged( double ); + void rightChanged( double ); + void topChanged( double ); + void bottomChanged( double ); + void orientationChanged( int ); + void setUnitInt( int unit ); + +private: + void updatePreview(); + void setValues(); + + KoUnit::Unit m_unit; + KoPageLayout m_layout; +}; + +#endif diff --git a/kexi/3rdparty/kolibs/Makefile.am b/kexi/3rdparty/kolibs/Makefile.am new file mode 100644 index 00000000..05d3fbd3 --- /dev/null +++ b/kexi/3rdparty/kolibs/Makefile.am @@ -0,0 +1,29 @@ +include $(top_srcdir)/kexi/Makefile.global + +noinst_LTLIBRARIES = libkexikolibs.la + +libkexikolibs_la_SOURCES = \ +koGlobal.cc \ +koUnit.cc \ +koUnitWidgets.cc \ +koPageLayoutDia.cc \ +KoPageLayoutColumnsBase.ui \ +KoPageLayoutColumns.cpp \ +koPageLayout.cpp \ +KoPageLayoutHeaderBase.ui \ +KoPageLayoutHeader.cpp \ +KoPageLayoutSize.cpp + +noinst_HEADERS = + +libkexikolibs_la_LDFLAGS = $(all_libraries) -Wnounresolved +libkexikolibs_la_LIBADD = +libkexikolibs_la_METASOURCES = AUTO + +SUBDIRS = . + +# set the include path for X, qt and KDE + +INCLUDES= -I$(top_srcdir)/kexi $(all_includes) + +KDE_CXXFLAGS += -DSIMPLE_KOLIBS -DKOFFICECORE_EXPORT= -DKOFFICEUI_EXPORT= diff --git a/kexi/3rdparty/kolibs/README b/kexi/3rdparty/kolibs/README new file mode 100644 index 00000000..0adb9905 --- /dev/null +++ b/kexi/3rdparty/kolibs/README @@ -0,0 +1,13 @@ +kexikolibs +---------- + +Maintained by: Jaroslaw Staniek, js at iidea . pl + + +This is a tiny selection of kofficeui and kofficecore classes taken +to reuse Page Layout dialog. + +Will be removed when packagers realize kofficelibs package should +be really shared among KOffice apps. + +The source code is almost unchanged except adding #ifdef SIMPLE_KOLIBS. diff --git a/kexi/3rdparty/kolibs/koGlobal.cc b/kexi/3rdparty/kolibs/koGlobal.cc new file mode 100644 index 00000000..09c74eab --- /dev/null +++ b/kexi/3rdparty/kolibs/koGlobal.cc @@ -0,0 +1,202 @@ +/* This file is part of the KDE project + Copyright (C) 2001 David Faure <faure@kde.org> + Copyright 2003 Nicolas GOUTTE <goutte@kde.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. +*/ + +#include "config.h" +#include <KoGlobal.h> +#include <kdebug.h> +#include <qfont.h> +#include <qfontinfo.h> +#include <kglobalsettings.h> +#include <kglobal.h> +#include <klocale.h> +#include <ksimpleconfig.h> +#include <kstandarddirs.h> +#include <kstaticdeleter.h> +#include <kimageio.h> +#include <kiconloader.h> +#include <kstandarddirs.h> + + +KoGlobal* KoGlobal::s_global = 0L; +static KStaticDeleter<KoGlobal> sdg; + +KoGlobal* KoGlobal::self() +{ + if ( !s_global ) + sdg.setObject( s_global, new KoGlobal ); + return s_global; +} + +KoGlobal::KoGlobal() + : m_pointSize( -1 ), m_kofficeConfig( 0L ) +{ + // Install the libkoffice* translations + KGlobal::locale()->insertCatalogue("koffice"); + + KImageIO::registerFormats(); + + // Tell KStandardDirs about the koffice prefix + KGlobal::dirs()->addPrefix(PREFIX); + + // Tell the iconloader about share/apps/koffice/icons + KGlobal::iconLoader()->addAppDir("koffice"); + + // Another way to get the DPI of the display would be QPaintDeviceMetrics, + // but we have no widget here (and moving this to KoView wouldn't allow + // using this from the document easily). +#ifdef Q_WS_X11 + m_dpiX = QPaintDevice::x11AppDpiX(); + m_dpiY = QPaintDevice::x11AppDpiY(); +#else + m_dpiX = 75; + m_dpiY = 75; +#endif +} + +KoGlobal::~KoGlobal() +{ + delete m_kofficeConfig; +} + +QFont KoGlobal::_defaultFont() +{ + QFont font = KGlobalSettings::generalFont(); + // we have to use QFontInfo, in case the font was specified with a pixel size + if ( font.pointSize() == -1 ) + { + // cache size into m_pointSize, since QFontInfo loads the font -> slow + if ( m_pointSize == -1 ) + m_pointSize = QFontInfo(font).pointSize(); + Q_ASSERT( m_pointSize != -1 ); + font.setPointSize( m_pointSize ); + } + //kdDebug()<<k_funcinfo<<"QFontInfo(font).pointSize() :"<<QFontInfo(font).pointSize()<<endl; + //kdDebug()<<k_funcinfo<<"font.name() :"<<font.family ()<<endl; + return font; +} + +QStringList KoGlobal::_listOfLanguageTags() +{ + if ( m_langMap.isEmpty() ) + createListOfLanguages(); + return m_langMap.values(); +} + +QStringList KoGlobal::_listOfLanguages() +{ + if ( m_langMap.empty() ) + createListOfLanguages(); + return m_langMap.keys(); +} + +void KoGlobal::createListOfLanguages() +{ + KConfig config( "all_languages", true, false, "locale" ); + // Note that we could also use KLocale::allLanguagesTwoAlpha + + QMap<QString, bool> seenLanguages; + const QStringList langlist = config.groupList(); + for ( QStringList::ConstIterator itall = langlist.begin(); + itall != langlist.end(); ++itall ) + { + const QString tag = *itall; + config.setGroup( tag ); + const QString name = config.readEntry("Name", tag); + // e.g. name is "French" and tag is "fr" + + // The QMap does the sorting on the display-name, so that + // comboboxes are sorted. + m_langMap.insert( name, tag ); + + seenLanguages.insert( tag, true ); + } + + // Also take a look at the installed translations. + // Many of them are already in all_languages but all_languages doesn't + // currently have en_GB or en_US etc. + + const QStringList translationList = KGlobal::dirs()->findAllResources("locale", + QString::fromLatin1("*/entry.desktop")); + for ( QStringList::ConstIterator it = translationList.begin(); + it != translationList.end(); ++it ) + { + // Extract the language tag from the directory name + QString tag = *it; + int index = tag.findRev('/'); + tag = tag.left(index); + index = tag.findRev('/'); + tag = tag.mid(index+1); + + if ( seenLanguages.find( tag ) == seenLanguages.end() ) { + KSimpleConfig entry(*it); + entry.setGroup("KCM Locale"); + + const QString name = entry.readEntry("Name", tag); + // e.g. name is "US English" and tag is "en_US" + m_langMap.insert( name, tag ); + + // enable this if writing a third way of finding languages below + //seenLanguages.insert( tag, true ); + } + + } + + // #### We also might not have an entry for a language where spellchecking is supported, + // but no KDE translation is available, like fr_CA. + // How to add them? +} + +QString KoGlobal::tagOfLanguage( const QString & _lang) +{ + const LanguageMap& map = self()->m_langMap; + QMap<QString,QString>::ConstIterator it = map.find( _lang ); + if ( it != map.end() ) + return *it; + return QString::null; +} + +QString KoGlobal::languageFromTag( const QString &langTag ) +{ + const LanguageMap& map = self()->m_langMap; + QMap<QString,QString>::ConstIterator it = map.begin(); + const QMap<QString,QString>::ConstIterator end = map.end(); + for ( ; it != end; ++it ) + if ( it.data() == langTag ) + return it.key(); + + // Language code not found. Better return the code (tag) than nothing. + return langTag; +} + +KConfig* KoGlobal::_kofficeConfig() +{ + if ( !m_kofficeConfig ) { + m_kofficeConfig = new KConfig( "kofficerc" ); + } + return m_kofficeConfig; +} + +void KoGlobal::setDPI( int x, int y ) +{ + //kdDebug() << k_funcinfo << x << "," << y << endl; + KoGlobal* s = self(); + s->m_dpiX = x; + s->m_dpiY = y; +} diff --git a/kexi/3rdparty/kolibs/koGlobal.h b/kexi/3rdparty/kolibs/koGlobal.h new file mode 100644 index 00000000..bab9c261 --- /dev/null +++ b/kexi/3rdparty/kolibs/koGlobal.h @@ -0,0 +1,107 @@ +/* This file is part of the KDE project + Copyright (C) 1998, 1999 Torben Weis <weis@kde.org> + Copyright 2002, 2003 David Faure <faure@kde.org> + Copyright 2003 Nicolas GOUTTE <goutte@kde.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. +*/ + +#ifndef koGlobal_h +#define koGlobal_h + +#include <qstringlist.h> +#include <qfont.h> +#include <qmap.h> +class KConfig; + +#include <koffice_export.h> +class KOFFICECORE_EXPORT KoGlobal +{ +public: + /// For KoApplication + static void initialize() { + (void)self(); // I don't want to make KGlobal instances public, so self() is private + } + /** + * Return the default font for KOffice programs. + * This is (currently) the same as the KDE-global default font, + * except that it is guaranteed to have a point size set, + * never a pixel size (see @ref QFont). + */ + static QFont defaultFont() { + return self()->_defaultFont(); + } + + /** + * @return the global KConfig object around kofficerc. + * kofficerc is used for KOffice-wide settings, from totally unrelated classes, + * so this is the centralization of the KConfig object so that the file is + * parsed only once + */ + static KConfig* kofficeConfig() { + return self()->_kofficeConfig(); + } + + static int dpiX() { + return self()->m_dpiX; + } + static int dpiY() { + return self()->m_dpiY; + } + /// @internal, for KoApplication + static void setDPI( int x, int y ); + + /// Return the list of available languages, in their displayable form + /// (translated names) + static QStringList listOfLanguages() { + return self()->_listOfLanguages(); + } + /// Return the list of available languages, in their internal form + /// e.g. "fr" or "en_US", here called "tag" + static QStringList listTagOfLanguages() { // TODO rename to listOfLanguageTags + return self()->_listOfLanguageTags(); + } + /// For a given language display name, return its tag + static QString tagOfLanguage( const QString & _lang ); + /// For a given language tag, return its display name + static QString languageFromTag( const QString &_lang ); + + ~KoGlobal(); + +private: + static KoGlobal* self(); + KoGlobal(); + QFont _defaultFont(); + QStringList _listOfLanguages(); + QStringList _listOfLanguageTags(); + KConfig* _kofficeConfig(); + void createListOfLanguages(); + + int m_pointSize; + typedef QMap<QString, QString> LanguageMap; + LanguageMap m_langMap; // display-name -> language tag + KConfig* m_kofficeConfig; + int m_dpiX; + int m_dpiY; + // No BC problem here, constructor is private, feel free to add members + + // Singleton pattern. Maybe this should even be refcounted, so + // that it gets cleaned up when closing all koffice parts in e.g. konqueror? + static KoGlobal* s_global; + friend class this_is_a_singleton; // work around gcc warning +}; + +#endif // koGlobal diff --git a/kexi/3rdparty/kolibs/koPageLayout.cpp b/kexi/3rdparty/kolibs/koPageLayout.cpp new file mode 100644 index 00000000..4ec985f3 --- /dev/null +++ b/kexi/3rdparty/kolibs/koPageLayout.cpp @@ -0,0 +1,244 @@ +/* This file is part of the KDE project + Copyright (C) 1998, 1999 Torben Weis <weis@kde.org> + Copyright 2002, 2003 David Faure <faure@kde.org> + Copyright 2003 Nicolas GOUTTE <goutte@kde.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. +*/ +#include "KoPageLayout.h" +#include <KoUnit.h> +#include <klocale.h> +#include <kprinter.h> +#include <kdebug.h> +#include <kglobal.h> +#ifndef SIMPLE_KOLIBS +# include <kodom.h> +# include <koxmlns.h> +#endif +#include <qdom.h> + +// paper formats ( mm ) +#define PG_A3_WIDTH 297.0 +#define PG_A3_HEIGHT 420.0 +#define PG_A4_WIDTH 210.0 +#define PG_A4_HEIGHT 297.0 +#define PG_A5_WIDTH 148.0 +#define PG_A5_HEIGHT 210.0 +#define PG_B5_WIDTH 182.0 +#define PG_B5_HEIGHT 257.0 +#define PG_US_LETTER_WIDTH 216.0 +#define PG_US_LETTER_HEIGHT 279.0 +#define PG_US_LEGAL_WIDTH 216.0 +#define PG_US_LEGAL_HEIGHT 356.0 +#define PG_US_EXECUTIVE_WIDTH 191.0 +#define PG_US_EXECUTIVE_HEIGHT 254.0 + +#ifndef SIMPLE_KOLIBS +KoGenStyle KoPageLayout::saveOasis() const +{ + KoGenStyle style(KoGenStyle::STYLE_PAGELAYOUT); + style.addPropertyPt("fo:page-width", ptWidth); + style.addPropertyPt("fo:page-height", ptHeight); + style.addPropertyPt("fo:margin-left", ptLeft); + style.addPropertyPt("fo:margin-right", ptRight); + style.addPropertyPt("fo:margin-top", ptTop); + style.addPropertyPt("fo:margin-bottom", ptBottom); + style.addProperty("style:print-orientation", (orientation == PG_LANDSCAPE ? "landscape" : "portrait")); + return style; +} + +void KoPageLayout::loadOasis(const QDomElement &style) +{ + QDomElement properties( KoDom::namedItemNS( style, KoXmlNS::style, "page-layout-properties" ) ); + if ( !properties.isNull() ) + { + ptWidth = KoUnit::parseValue(properties.attributeNS( KoXmlNS::fo, "page-width", QString::null ) ); + ptHeight = KoUnit::parseValue(properties.attributeNS( KoXmlNS::fo, "page-height", QString::null ) ); + if (properties.attributeNS( KoXmlNS::style, "print-orientation", QString::null)=="portrait") + orientation=PG_PORTRAIT; + else + orientation=PG_LANDSCAPE; + ptRight = KoUnit::parseValue( properties.attributeNS( KoXmlNS::fo, "margin-right", QString::null ) ); + ptBottom = KoUnit::parseValue( properties.attributeNS( KoXmlNS::fo, "margin-bottom", QString::null ) ); + ptLeft = KoUnit::parseValue( properties.attributeNS( KoXmlNS::fo, "margin-left", QString::null ) ); + ptTop = KoUnit::parseValue( properties.attributeNS( KoXmlNS::fo, "margin-top", QString::null ) ); + // guessFormat takes millimeters + if ( orientation == PG_LANDSCAPE ) + format = KoPageFormat::guessFormat( POINT_TO_MM(ptHeight), POINT_TO_MM(ptWidth) ); + else + format = KoPageFormat::guessFormat( POINT_TO_MM(ptWidth), POINT_TO_MM(ptHeight) ); + } +} +#endif + +KoPageLayout KoPageLayout::standardLayout() +{ + KoPageLayout layout; + layout.format = KoPageFormat::defaultFormat(); + layout.orientation = PG_PORTRAIT; + layout.ptWidth = MM_TO_POINT( KoPageFormat::width( layout.format, layout.orientation ) ); + layout.ptHeight = MM_TO_POINT( KoPageFormat::height( layout.format, layout.orientation ) ); + layout.ptLeft = MM_TO_POINT( 20.0 ); + layout.ptRight = MM_TO_POINT( 20.0 ); + layout.ptTop = MM_TO_POINT( 20.0 ); + layout.ptBottom = MM_TO_POINT( 20.0 ); + return layout; +} + +struct PageFormatInfo +{ + KoFormat format; + KPrinter::PageSize kprinter; + const char* shortName; // Short name + const char* descriptiveName; // Full name, which will be translated + double width; // in mm + double height; // in mm +}; + +// NOTES: +// - the width and height of non-ISO formats are rounded +// http://en.wikipedia.org/wiki/Paper_size can help +// - the comments "should be..." indicates the exact values if the inch sizes would be multiplied by 25.4 mm/inch + +const PageFormatInfo pageFormatInfo[]= +{ + { PG_DIN_A3, KPrinter::A3, "A3", I18N_NOOP("ISO A3"), 297.0, 420.0 }, + { PG_DIN_A4, KPrinter::A4, "A4", I18N_NOOP("ISO A4"), 210.0, 297.0 }, + { PG_DIN_A5, KPrinter::A5, "A5", I18N_NOOP("ISO A5"), 148.0, 210.0 }, + { PG_US_LETTER, KPrinter::Letter, "Letter", I18N_NOOP("US Letter"), 215.9, 279.4 }, + { PG_US_LEGAL, KPrinter::Legal, "Legal", I18N_NOOP("US Legal"), 215.9, 355.6 }, + { PG_SCREEN, KPrinter::A4, "Screen", I18N_NOOP("Screen"), PG_A4_HEIGHT, PG_A4_WIDTH }, // Custom, so fall back to A4 + { PG_CUSTOM, KPrinter::A4, "Custom", I18N_NOOP2("Custom size", "Custom"), PG_A4_WIDTH, PG_A4_HEIGHT }, // Custom, so fall back to A4 + { PG_DIN_B5, KPrinter::B5, "B5", I18N_NOOP("ISO B5"), 182.0, 257.0 }, + // Hmm, wikipedia says 184.15 * 266.7 for executive ! + { PG_US_EXECUTIVE, KPrinter::Executive, "Executive", I18N_NOOP("US Executive"), 191.0, 254.0 }, // should be 190.5 mm x 254.0 mm + { PG_DIN_A0, KPrinter::A0, "A0", I18N_NOOP("ISO A0"), 841.0, 1189.0 }, + { PG_DIN_A1, KPrinter::A1, "A1", I18N_NOOP("ISO A1"), 594.0, 841.0 }, + { PG_DIN_A2, KPrinter::A2, "A2", I18N_NOOP("ISO A2"), 420.0, 594.0 }, + { PG_DIN_A6, KPrinter::A6, "A6", I18N_NOOP("ISO A6"), 105.0, 148.0 }, + { PG_DIN_A7, KPrinter::A7, "A7", I18N_NOOP("ISO A7"), 74.0, 105.0 }, + { PG_DIN_A8, KPrinter::A8, "A8", I18N_NOOP("ISO A8"), 52.0, 74.0 }, + { PG_DIN_A9, KPrinter::A9, "A9", I18N_NOOP("ISO A9"), 37.0, 52.0 }, + { PG_DIN_B0, KPrinter::B0, "B0", I18N_NOOP("ISO B0"), 1030.0, 1456.0 }, + { PG_DIN_B1, KPrinter::B1, "B1", I18N_NOOP("ISO B1"), 728.0, 1030.0 }, + { PG_DIN_B10, KPrinter::B10, "B10", I18N_NOOP("ISO B10"), 32.0, 45.0 }, + { PG_DIN_B2, KPrinter::B2, "B2", I18N_NOOP("ISO B2"), 515.0, 728.0 }, + { PG_DIN_B3, KPrinter::B3, "B3", I18N_NOOP("ISO B3"), 364.0, 515.0 }, + { PG_DIN_B4, KPrinter::B4, "B4", I18N_NOOP("ISO B4"), 257.0, 364.0 }, + { PG_DIN_B6, KPrinter::B6, "B6", I18N_NOOP("ISO B6"), 128.0, 182.0 }, + { PG_ISO_C5, KPrinter::C5E, "C5", I18N_NOOP("ISO C5"), 163.0, 229.0 }, // Some sources tells: 162 mm x 228 mm + { PG_US_COMM10, KPrinter::Comm10E, "Comm10", I18N_NOOP("US Common 10"), 105.0, 241.0 }, // should be 104.775 mm x 241.3 mm + { PG_ISO_DL, KPrinter::DLE, "DL", I18N_NOOP("ISO DL"), 110.0, 220.0 }, + { PG_US_FOLIO, KPrinter::Folio, "Folio", I18N_NOOP("US Folio"), 210.0, 330.0 }, // should be 209.54 mm x 330.2 mm + { PG_US_LEDGER, KPrinter::Ledger, "Ledger", I18N_NOOP("US Ledger"), 432.0, 279.0 }, // should be 431.8 mm x 297.4 mm + { PG_US_TABLOID, KPrinter::Tabloid, "Tabloid", I18N_NOOP("US Tabloid"), 279.0, 432.0 } // should be 297.4 mm x 431.8 mm +}; + +int KoPageFormat::printerPageSize( KoFormat format ) +{ + if ( format == PG_SCREEN ) + { + kdWarning() << "You use the page layout SCREEN. Printing in DIN A4 LANDSCAPE." << endl; + return KPrinter::A4; + } + else if ( format == PG_CUSTOM ) + { + kdWarning() << "The used page layout (CUSTOM) is not supported by KPrinter. Printing in A4." << endl; + return KPrinter::A4; + } + else if ( format <= PG_LAST_FORMAT ) + return pageFormatInfo[ format ].kprinter; + else + return KPrinter::A4; +} + +double KoPageFormat::width( KoFormat format, KoOrientation orientation ) +{ + if ( orientation == PG_LANDSCAPE ) + return height( format, PG_PORTRAIT ); + if ( format <= PG_LAST_FORMAT ) + return pageFormatInfo[ format ].width; + return PG_A4_WIDTH; // should never happen +} + +double KoPageFormat::height( KoFormat format, KoOrientation orientation ) +{ + if ( orientation == PG_LANDSCAPE ) + return width( format, PG_PORTRAIT ); + if ( format <= PG_LAST_FORMAT ) + return pageFormatInfo[ format ].height; + return PG_A4_HEIGHT; +} + +KoFormat KoPageFormat::guessFormat( double width, double height ) +{ + for ( int i = 0 ; i <= PG_LAST_FORMAT ; ++i ) + { + // We have some tolerance. 1pt is a third of a mm, this is + // barely noticeable for a page size. + if ( i != PG_CUSTOM + && kAbs( width - pageFormatInfo[i].width ) < 1.0 + && kAbs( height - pageFormatInfo[i].height ) < 1.0 ) + return static_cast<KoFormat>(i); + } + return PG_CUSTOM; +} + +QString KoPageFormat::formatString( KoFormat format ) +{ + if ( format <= PG_LAST_FORMAT ) + return QString::fromLatin1( pageFormatInfo[ format ].shortName ); + return QString::fromLatin1( "A4" ); +} + +KoFormat KoPageFormat::formatFromString( const QString & string ) +{ + for ( int i = 0 ; i <= PG_LAST_FORMAT ; ++i ) + { + if (string == QString::fromLatin1( pageFormatInfo[ i ].shortName )) + return pageFormatInfo[ i ].format; + } + // We do not know the format name, so we have a custom format + return PG_CUSTOM; +} + +KoFormat KoPageFormat::defaultFormat() +{ + int kprinter = KGlobal::locale()->pageSize(); + for ( int i = 0 ; i <= PG_LAST_FORMAT ; ++i ) + { + if ( pageFormatInfo[ i ].kprinter == kprinter ) + return static_cast<KoFormat>(i); + } + return PG_DIN_A4; +} + +QString KoPageFormat::name( KoFormat format ) +{ + if ( format <= PG_LAST_FORMAT ) + return i18n( pageFormatInfo[ format ].descriptiveName ); + return i18n( pageFormatInfo[ PG_DIN_A4 ].descriptiveName ); +} + +QStringList KoPageFormat::allFormats() +{ + QStringList lst; + for ( int i = 0 ; i <= PG_LAST_FORMAT ; ++i ) + { + lst << i18n( pageFormatInfo[ i ].descriptiveName ); + } + return lst; +} diff --git a/kexi/3rdparty/kolibs/koPageLayout.h b/kexi/3rdparty/kolibs/koPageLayout.h new file mode 100644 index 00000000..b526620e --- /dev/null +++ b/kexi/3rdparty/kolibs/koPageLayout.h @@ -0,0 +1,260 @@ +/* This file is part of the KDE project + Copyright (C) 1998, 1999 Torben Weis <weis@kde.org> + Copyright 2002, 2003 David Faure <faure@kde.org> + Copyright 2003 Nicolas GOUTTE <goutte@kde.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. +*/ + +#ifndef KOPAGELAYOUT_H +#define KOPAGELAYOUT_H + +#ifndef SIMPLE_KOLIBS +# include <koGenStyles.h> +#endif +#include <qstringlist.h> +#include <koffice_export.h> +class QDomElement; + +/** + * @brief Represents the paper format a document shall be printed on. + * + * For compatibility reasons, and because of screen and custom, + * this enum doesn't map to QPrinter::PageSize but KoPageFormat::printerPageSize + * does the conversion. + * + * @todo convert DIN to ISO in the names + */ +enum KoFormat { + PG_DIN_A3 = 0, + PG_DIN_A4 = 1, + PG_DIN_A5 = 2, + PG_US_LETTER = 3, + PG_US_LEGAL = 4, + PG_SCREEN = 5, + PG_CUSTOM = 6, + PG_DIN_B5 = 7, + PG_US_EXECUTIVE = 8, + PG_DIN_A0 = 9, + PG_DIN_A1 = 10, + PG_DIN_A2 = 11, + PG_DIN_A6 = 12, + PG_DIN_A7 = 13, + PG_DIN_A8 = 14, + PG_DIN_A9 = 15, + PG_DIN_B0 = 16, + PG_DIN_B1 = 17, + PG_DIN_B10 = 18, + PG_DIN_B2 = 19, + PG_DIN_B3 = 20, + PG_DIN_B4 = 21, + PG_DIN_B6 = 22, + PG_ISO_C5 = 23, + PG_US_COMM10 = 24, + PG_ISO_DL = 25, + PG_US_FOLIO = 26, + PG_US_LEDGER = 27, + PG_US_TABLOID = 28, + // update the number below and the static arrays if you add more values to the enum + PG_LAST_FORMAT = PG_US_TABLOID // used by koPageLayout.cpp +}; + +/** + * Represents the orientation of a printed document. + */ +enum KoOrientation { + PG_PORTRAIT = 0, + PG_LANDSCAPE = 1 +}; + +namespace KoPageFormat +{ + /** + * @brief Convert a KoFormat into a KPrinter::PageSize. + * + * If format is 'screen' it will use A4 landscape. + * If format is 'custom' it will use A4 portrait. + * (you may want to take care of those cases separately). + * Usually passed to KPrinter::setPageSize(). + * + * @note We return int instead of the enum to avoid including kprinter.h + */ + KOFFICECORE_EXPORT int /*KPrinter::PageSize*/ printerPageSize( KoFormat format ); + + /** + * Returns the width (in mm) for a given page format and orientation + * 'Custom' isn't supported by this function, obviously. + */ + KOFFICECORE_EXPORT double width( KoFormat format, KoOrientation orientation ); + + /** + * Returns the height (in mm) for a given page format and orientation + * 'Custom' isn't supported by this function, obviously. + */ + KOFFICECORE_EXPORT double height( KoFormat format, KoOrientation orientation ); + + /** + * Returns the internal name of the given page format. + * Use for saving. + */ + KOFFICECORE_EXPORT QString formatString( KoFormat format ); + + /** + * Convert a format string (internal name) to a page format value. + * Use for loading. + */ + KOFFICECORE_EXPORT KoFormat formatFromString( const QString & string ); + + /** + * Returns the default format (based on the KControl settings) + */ + KOFFICECORE_EXPORT KoFormat defaultFormat(); + + /** + * Returns the translated name of the given page format. + * Use for showing the user. + */ + KOFFICECORE_EXPORT QString name( KoFormat format ); + + /** + * Lists the translated names of all the available formats + */ + KOFFICECORE_EXPORT QStringList allFormats(); + + /** + * Try to find the paper format for the given width and height (in mm). + * Useful to some import filters. + */ + KOFFICECORE_EXPORT KoFormat guessFormat( double width, double height ); +} + + +/** + * @brief Header/Footer type. + * + * @note Yes, this should have been a bitfield, but there was only 0, 2, 3 in koffice-1.0. Don't ask why. + * In the long run this should be replaced with a more flexible repetition/section concept. + */ +enum KoHFType { + HF_SAME = 0, ///< 0: Header/Footer is the same on all pages + HF_FIRST_EO_DIFF = 1, ///< 1: Header/Footer is different on first, even and odd pages (2&3) + HF_FIRST_DIFF = 2, ///< 2: Header/Footer for the first page differs + HF_EO_DIFF = 3 ///< 3: Header/Footer for even - odd pages are different +}; + +/** + * This structure defines the page layout, including + * its size in pt, its format (e.g. A4), orientation, unit, margins etc. + */ +struct KoPageLayout +{ + /** Page format */ + KoFormat format; + /** Page orientation */ + KoOrientation orientation; + + /** Page width in pt */ + double ptWidth; + /** Page height in pt */ + double ptHeight; + /** Left margin in pt */ + double ptLeft; + /** Right margin in pt */ + double ptRight; + /** Top margin in pt */ + double ptTop; + /** Bottom margin in pt */ + double ptBottom; + + bool operator==( const KoPageLayout& l ) const { + return ( ptWidth == l.ptWidth && + ptHeight == l.ptHeight && + ptLeft == l.ptLeft && + ptRight == l.ptRight && + ptTop == l.ptTop && + ptBottom == l.ptBottom ); + } + bool operator!=( const KoPageLayout& l ) const { + return !( (*this) == l ); + } + +#ifndef SIMPLE_KOLIBS + /** + * Save this page layout to OASIS. + */ + KOFFICECORE_EXPORT KoGenStyle saveOasis() const; + + /** + * Load this page layout from OASIS + */ + KOFFICECORE_EXPORT void loadOasis(const QDomElement &style); +#endif + + /** + * @return a page layout with the default page size depending on the locale settings, + * default margins (2 cm), and portrait orientation. + * @since 1.4 + */ + static KOFFICECORE_EXPORT KoPageLayout standardLayout(); +}; + +/** structure for header-footer */ +struct KoHeadFoot +{ + QString headLeft; + QString headMid; + QString headRight; + QString footLeft; + QString footMid; + QString footRight; +}; + +/** structure for columns */ +struct KoColumns +{ + int columns; + double ptColumnSpacing; + bool operator==( const KoColumns& rhs ) const { + return columns == rhs.columns && + QABS(ptColumnSpacing - rhs.ptColumnSpacing) <= 1E-10; + } + bool operator!=( const KoColumns& rhs ) const { + return columns != rhs.columns || + QABS(ptColumnSpacing - rhs.ptColumnSpacing) > 1E-10; + } +}; + +/** structure for KWord header-footer */ +struct KoKWHeaderFooter +{ + KoHFType header; + KoHFType footer; + double ptHeaderBodySpacing; + double ptFooterBodySpacing; + double ptFootNoteBodySpacing; + bool operator==( const KoKWHeaderFooter& rhs ) const { + return header == rhs.header && footer == rhs.footer && + QABS(ptHeaderBodySpacing - rhs.ptHeaderBodySpacing) <= 1E-10 && + QABS(ptFooterBodySpacing - rhs.ptFooterBodySpacing) <= 1E-10 && + QABS(ptFootNoteBodySpacing - rhs.ptFootNoteBodySpacing) <= 1E-10; + } + bool operator!=( const KoKWHeaderFooter& rhs ) const { + return !( *this == rhs ); + } +}; + +#endif /* KOPAGELAYOUT_H */ + diff --git a/kexi/3rdparty/kolibs/koPageLayoutDia.cc b/kexi/3rdparty/kolibs/koPageLayoutDia.cc new file mode 100644 index 00000000..5fe8832e --- /dev/null +++ b/kexi/3rdparty/kolibs/koPageLayoutDia.cc @@ -0,0 +1,402 @@ +/* This file is part of the KDE project + Copyright (C) 1998, 1999 Reginald Stadlbauer <reggie@kde.org> + Copyright (C) 2005 Thomas Zander <zander@kde.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. +*/ + +// Description: Page Layout Dialog (sources) + +/******************************************************************/ + +#include <KoPageLayoutDia.h> +#include <KoPageLayoutColumns.h> +#include <KoPageLayoutSize.h> +#include <KoPageLayoutHeader.h> +#include <KoUnit.h> +#include <KoUnitWidgets.h> + +#include <klocale.h> +#include <kiconloader.h> +#include <kmessagebox.h> + +#include <qlabel.h> +#include <qlayout.h> +#include <qpainter.h> +#include <qlineedit.h> +#include <qbuttongroup.h> +#include <qradiobutton.h> +#include <qcheckbox.h> +#include <qhbox.h> +#include <qvgroupbox.h> +#include <qhbuttongroup.h> + +/******************************************************************/ +/* class KoPagePreview */ +/******************************************************************/ + +/*===================== constrcutor ==============================*/ +KoPagePreview::KoPagePreview( QWidget* parent, const char *name, const KoPageLayout& layout ) + : QGroupBox( i18n( "Page Preview" ), parent, name ) +{ + setPageLayout( layout ); + columns = 1; + setMinimumSize( 150, 150 ); +} + +/*====================== destructor ==============================*/ +KoPagePreview::~KoPagePreview() +{ +} + +/*=================== set layout =================================*/ +void KoPagePreview::setPageLayout( const KoPageLayout &layout ) +{ + // resolution[XY] is in pixel per pt + double resolutionX = POINT_TO_INCH( static_cast<double>(KoGlobal::dpiX()) ); + double resolutionY = POINT_TO_INCH( static_cast<double>(KoGlobal::dpiY()) ); + + m_pageWidth = layout.ptWidth * resolutionX; + m_pageHeight = layout.ptHeight * resolutionY; + + double zh = 110.0 / m_pageHeight; + double zw = 110.0 / m_pageWidth; + double z = QMIN( zw, zh ); + + m_pageWidth *= z; + m_pageHeight *= z; + + m_textFrameX = layout.ptLeft * resolutionX * z; + m_textFrameY = layout.ptTop * resolutionY * z; + m_textFrameWidth = m_pageWidth - ( layout.ptLeft + layout.ptRight ) * resolutionX * z; + m_textFrameHeight = m_pageHeight - ( layout.ptTop + layout.ptBottom ) * resolutionY * z; + + repaint( true ); +} + +/*=================== set layout =================================*/ +void KoPagePreview::setPageColumns( const KoColumns &_columns ) +{ + columns = _columns.columns; + repaint( true ); +} + +/*======================== draw contents =========================*/ +void KoPagePreview::drawContents( QPainter *painter ) +{ + double cw = m_textFrameWidth; + if(columns!=1) + cw/=static_cast<double>(columns); + + painter->setBrush( white ); + painter->setPen( QPen( black ) ); + + int x=static_cast<int>( ( width() - m_pageWidth ) * 0.5 ); + int y=static_cast<int>( ( height() - m_pageHeight ) * 0.5 ); + int w=static_cast<int>(m_pageWidth); + int h=static_cast<int>(m_pageHeight); + //painter->drawRect( x + 1, y + 1, w, h); + painter->drawRect( x, y, w, h ); + + painter->setBrush( QBrush( black, HorPattern ) ); + if ( m_textFrameWidth == m_pageWidth || m_textFrameHeight == m_pageHeight ) + painter->setPen( NoPen ); + else + painter->setPen( lightGray ); + + for ( int i = 0; i < columns; ++i ) + painter->drawRect( x + static_cast<int>(m_textFrameX) + static_cast<int>(i * cw), + y + static_cast<int>(m_textFrameY), static_cast<int>(cw), + static_cast<int>(m_textFrameHeight) ); +} + +/******************************************************************/ +/* class KoPageLayoutDia */ +/******************************************************************/ + +/*==================== constructor ===============================*/ +KoPageLayoutDia::KoPageLayoutDia( QWidget* parent, const char* name, + const KoPageLayout& layout, + const KoHeadFoot& hf, int tabs, + KoUnit::Unit unit, bool modal ) + : KDialogBase( KDialogBase::Tabbed, i18n("Page Layout"), KDialogBase::Ok | KDialogBase::Cancel, + KDialogBase::Ok, parent, name, modal) +{ + + flags = tabs; + m_layout = layout; + m_unit = unit; + m_pageSizeTab = 0; + m_columnsTab = 0; + m_headerTab = 0; + + m_column.columns = 1; + + if ( tabs & FORMAT_AND_BORDERS ) setupTab1( true ); + if ( tabs & HEADER_AND_FOOTER ) setupTab2( hf ); + + setFocusPolicy( QWidget::StrongFocus ); + setFocus(); +} + +/*==================== constructor ===============================*/ +KoPageLayoutDia::KoPageLayoutDia( QWidget* parent, const char* name, + const KoPageLayout& layout, + const KoHeadFoot& hf, + const KoColumns& columns, + const KoKWHeaderFooter& kwhf, + int tabs, KoUnit::Unit unit ) + : KDialogBase( KDialogBase::Tabbed, i18n("Page Layout"), KDialogBase::Ok | KDialogBase::Cancel, + KDialogBase::Ok, parent, name, true) +{ + flags = tabs; + + m_layout = layout; + m_column = columns; + m_unit = unit; + m_pageSizeTab = 0; + m_columnsTab = 0; + m_headerTab = 0; + + if ( tabs & FORMAT_AND_BORDERS ) setupTab1( !( tabs & DISABLE_BORDERS ) ); + if ( tabs & HEADER_AND_FOOTER ) setupTab2( hf ); + if ( tabs & COLUMNS ) setupTab3(); + if ( tabs & KW_HEADER_AND_FOOTER ) setupTab4(kwhf); + + setFocusPolicy( QWidget::StrongFocus ); + setFocus(); +} + +/*===================== destructor ===============================*/ +KoPageLayoutDia::~KoPageLayoutDia() +{ +} + +/*======================= show dialog ============================*/ +bool KoPageLayoutDia::pageLayout( KoPageLayout& layout, KoHeadFoot& hf, int tabs, KoUnit::Unit& unit, QWidget* parent ) +{ + bool res = false; + KoPageLayoutDia *dlg = new KoPageLayoutDia( parent, "PageLayout", layout, hf, tabs, unit ); + + if ( dlg->exec() == QDialog::Accepted ) { + res = true; + if ( tabs & FORMAT_AND_BORDERS ) layout = dlg->layout(); + if ( tabs & HEADER_AND_FOOTER ) hf = dlg->headFoot(); + unit = dlg->unit(); + } + + delete dlg; + + return res; +} + +/*======================= show dialog ============================*/ +bool KoPageLayoutDia::pageLayout( KoPageLayout& layout, KoHeadFoot& hf, KoColumns& columns, + KoKWHeaderFooter &_kwhf, int tabs, KoUnit::Unit& unit, QWidget* parent ) +{ + bool res = false; + KoPageLayoutDia *dlg = new KoPageLayoutDia( parent, "PageLayout", layout, hf, columns, _kwhf, tabs, unit ); + + if ( dlg->exec() == QDialog::Accepted ) { + res = true; + if ( tabs & FORMAT_AND_BORDERS ) layout = dlg->layout(); + if ( tabs & HEADER_AND_FOOTER ) hf = dlg->headFoot(); + if ( tabs & COLUMNS ) columns = dlg->columns(); + if ( tabs & KW_HEADER_AND_FOOTER ) _kwhf = dlg->headerFooter(); + unit = dlg->unit(); + } + + delete dlg; + + return res; +} + +/*===================== get a standard page layout ===============*/ +KoPageLayout KoPageLayoutDia::standardLayout() +{ + return KoPageLayout::standardLayout(); +} + +/*====================== get header - footer =====================*/ +KoHeadFoot KoPageLayoutDia::headFoot() const +{ + KoHeadFoot hf; + hf.headLeft = eHeadLeft->text(); + hf.headMid = eHeadMid->text(); + hf.headRight = eHeadRight->text(); + hf.footLeft = eFootLeft->text(); + hf.footMid = eFootMid->text(); + hf.footRight = eFootRight->text(); + return hf; +} + +/*================================================================*/ +const KoKWHeaderFooter& KoPageLayoutDia::headerFooter() +{ + return m_headerTab->headerFooter(); +} + +/*================ setup page size & margins tab ==================*/ +void KoPageLayoutDia::setupTab1( bool enableBorders ) +{ + QWidget *tab1 = addPage(i18n( "Page Size && &Margins" )); + QHBoxLayout *lay = new QHBoxLayout(tab1); + m_pageSizeTab = new KoPageLayoutSize(tab1, m_layout, m_unit, m_column, !(flags & DISABLE_UNIT), enableBorders ); + lay->addWidget(m_pageSizeTab); + m_pageSizeTab->show(); + connect (m_pageSizeTab, SIGNAL( propertyChange(KoPageLayout&)), + this, SLOT (sizeUpdated( KoPageLayout&))); +} + +void KoPageLayoutDia::sizeUpdated(KoPageLayout &layout) { + m_layout.ptWidth = layout.ptWidth; + m_layout.ptHeight = layout.ptHeight; + m_layout.ptLeft = layout.ptLeft; + m_layout.ptRight = layout.ptRight; + m_layout.ptTop = layout.ptTop; + m_layout.ptBottom = layout.ptBottom; + m_layout.format = layout.format; + m_layout.orientation = layout.orientation; + if(m_columnsTab) + m_columnsTab->setLayout(layout); +} + +/*================ setup header and footer tab ===================*/ +void KoPageLayoutDia::setupTab2( const KoHeadFoot& hf ) +{ + QWidget *tab2 = addPage(i18n( "H&eader && Footer" )); + QGridLayout *grid2 = new QGridLayout( tab2, 7, 2, 0, KDialog::spacingHint() ); + + // ------------- header --------------- + QGroupBox *gHead = new QGroupBox( 0, Qt::Vertical, i18n( "Head Line" ), tab2 ); + gHead->layout()->setSpacing(KDialog::spacingHint()); + gHead->layout()->setMargin(KDialog::marginHint()); + QGridLayout *headGrid = new QGridLayout( gHead->layout(), 2, 3 ); + + QLabel *lHeadLeft = new QLabel( i18n( "Left:" ), gHead ); + headGrid->addWidget( lHeadLeft, 0, 0 ); + + eHeadLeft = new QLineEdit( gHead ); + headGrid->addWidget( eHeadLeft, 1, 0 ); + eHeadLeft->setText( hf.headLeft ); + + QLabel *lHeadMid = new QLabel( i18n( "Mid:" ), gHead ); + headGrid->addWidget( lHeadMid, 0, 1 ); + + eHeadMid = new QLineEdit( gHead ); + headGrid->addWidget( eHeadMid, 1, 1 ); + eHeadMid->setText( hf.headMid ); + + QLabel *lHeadRight = new QLabel( i18n( "Right:" ), gHead ); + headGrid->addWidget( lHeadRight, 0, 2 ); + + eHeadRight = new QLineEdit( gHead ); + headGrid->addWidget( eHeadRight, 1, 2 ); + eHeadRight->setText( hf.headRight ); + + grid2->addMultiCellWidget( gHead, 0, 1, 0, 1 ); + + // ------------- footer --------------- + QGroupBox *gFoot = new QGroupBox( 0, Qt::Vertical, i18n( "Foot Line" ), tab2 ); + gFoot->layout()->setSpacing(KDialog::spacingHint()); + gFoot->layout()->setMargin(KDialog::marginHint()); + QGridLayout *footGrid = new QGridLayout( gFoot->layout(), 2, 3 ); + + QLabel *lFootLeft = new QLabel( i18n( "Left:" ), gFoot ); + footGrid->addWidget( lFootLeft, 0, 0 ); + + eFootLeft = new QLineEdit( gFoot ); + footGrid->addWidget( eFootLeft, 1, 0 ); + eFootLeft->setText( hf.footLeft ); + + QLabel *lFootMid = new QLabel( i18n( "Mid:" ), gFoot ); + footGrid->addWidget( lFootMid, 0, 1 ); + + eFootMid = new QLineEdit( gFoot ); + footGrid->addWidget( eFootMid, 1, 1 ); + eFootMid->setText( hf.footMid ); + + QLabel *lFootRight = new QLabel( i18n( "Right:" ), gFoot ); + footGrid->addWidget( lFootRight, 0, 2 ); + + eFootRight = new QLineEdit( gFoot ); + footGrid->addWidget( eFootRight, 1, 2 ); + eFootRight->setText( hf.footRight ); + + grid2->addMultiCellWidget( gFoot, 2, 3, 0, 1 ); + + QLabel *lMacros2 = new QLabel( i18n( "You can insert several tags in the text:" ), tab2 ); + grid2->addMultiCellWidget( lMacros2, 4, 4, 0, 1 ); + + QLabel *lMacros3 = new QLabel( i18n("<qt><ul><li><sheet> The sheet name</li>" + "<li><page> The current page</li>" + "<li><pages> The total number of pages</li>" + "<li><name> The filename or URL</li>" + "<li><file> The filename with complete path or the URL</li></ul></qt>"), tab2 ); + grid2->addMultiCellWidget( lMacros3, 5, 6, 0, 0, Qt::AlignTop ); + + QLabel *lMacros4 = new QLabel( i18n("<qt><ul><li><time> The current time</li>" + "<li><date> The current date</li>" + "<li><author> Your full name</li>" + "<li><org> Your organization</li>" + "<li><email> Your email address</li></ul></qt>"), tab2 ); + grid2->addMultiCellWidget( lMacros4, 5, 6, 1, 1, Qt::AlignTop ); +} + +/*================================================================*/ +void KoPageLayoutDia::setupTab3() +{ + QWidget *tab3 = addPage(i18n( "Col&umns" )); + QHBoxLayout *lay = new QHBoxLayout(tab3); + m_columnsTab = new KoPageLayoutColumns(tab3, m_column, m_unit, m_layout); + m_columnsTab->layout()->setMargin(0); + lay->addWidget(m_columnsTab); + m_columnsTab->show(); + connect (m_columnsTab, SIGNAL( propertyChange(KoColumns&)), + this, SLOT (columnsUpdated( KoColumns&))); +} + +void KoPageLayoutDia::columnsUpdated(KoColumns &columns) { + m_column.columns = columns.columns; + m_column.ptColumnSpacing = columns.ptColumnSpacing; + if(m_pageSizeTab) + m_pageSizeTab->setColumns(columns); +} + +/*================================================================*/ +void KoPageLayoutDia::setupTab4(const KoKWHeaderFooter kwhf ) +{ + QWidget *tab4 = addPage(i18n( "H&eader && Footer" )); + QHBoxLayout *lay = new QHBoxLayout(tab4); + m_headerTab = new KoPageLayoutHeader(tab4, m_unit, kwhf); + m_headerTab->layout()->setMargin(0); + lay->addWidget(m_headerTab); + m_headerTab->show(); + +} + + +/* Validation when closing. Error messages are never liked, but + better let the users enter all values in any order, and have one + final validation, than preventing them from entering values. */ +void KoPageLayoutDia::slotOk() +{ + if( m_pageSizeTab ) + m_pageSizeTab->queryClose(); + KDialogBase::slotOk(); // accept +} + +#include <koPageLayoutDia.moc> diff --git a/kexi/3rdparty/kolibs/koPageLayoutDia.h b/kexi/3rdparty/kolibs/koPageLayoutDia.h new file mode 100644 index 00000000..f3f1d932 --- /dev/null +++ b/kexi/3rdparty/kolibs/koPageLayoutDia.h @@ -0,0 +1,200 @@ +/* This file is part of the KDE project + Copyright (C) 1998, 1999 Reginald Stadlbauer <reggie@kde.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. +*/ + +// Description: Page Layout Dialog (header) + +#ifndef __KOPGLAYOUTDIA_H__ +#define __KOPGLAYOUTDIA_H__ + +#include <qgroupbox.h> +#include <KoGlobal.h> +#include <KoUnit.h> +#include <kdialogbase.h> +#include <KoPageLayout.h> + +class QButtonGroup; +class QComboBox; +class QLineEdit; +class QCheckBox; +class KoUnitDoubleSpinBox; +class KoPageLayoutColumns; +class KoPageLayoutSize; +class KoPageLayoutHeader; + +enum { FORMAT_AND_BORDERS = 1, HEADER_AND_FOOTER = 2, COLUMNS = 4, DISABLE_BORDERS = 8, + KW_HEADER_AND_FOOTER = 16, DISABLE_UNIT = 32 }; + +/** + * KoPagePreview. + * Internal to KoPageLayoutDia. + */ +class KoPagePreview : public QGroupBox +{ + Q_OBJECT + +public: + + /** + * constructor + */ + KoPagePreview( QWidget*, const char*, const KoPageLayout & ); + /** + * destructor + */ + ~KoPagePreview(); + + /** + * set page layout + */ + void setPageLayout( const KoPageLayout& ); + void setPageColumns( const KoColumns& ); + +protected: + + // paint page + void drawContents( QPainter* ); + + double m_pageHeight, m_pageWidth, m_textFrameX, m_textFrameY, m_textFrameWidth, m_textFrameHeight; + int columns; +}; + +class KoPageLayoutDiaPrivate; + +/** + * With this dialog the user can specify the layout of the paper during printing. + */ +class KOFFICEUI_EXPORT KoPageLayoutDia : public KDialogBase +{ + Q_OBJECT + +public: + + /** + * Constructor. + * + * @param parent The parent of the dialog. + * @param name The name of the dialog. + * @param layout The layout. + * @param headfoot The header and the footer. + * @param flags a variable with all features this dialog should show. + * @param unit The unit to use for displaying the values to the user. + * @param modal Whether the dialog is modal or not. + */ + KoPageLayoutDia( QWidget* parent, const char* name, + const KoPageLayout& layout, + const KoHeadFoot& headfoot, + int flags, KoUnit::Unit unit, bool modal=true ); + + /** + * Constructor. + * + * @param parent The parent of the dialog. + * @param name The name of the dialog. + * @param layout The layout. + * @param headfoot The header and the footer. + * @param columns The number of columns on the page. + * @param kwheadfoot The KWord header and footer. + * @param tabs The number of tabs. + * @param unit The unit to use for displaying the values to the user + */ + KoPageLayoutDia( QWidget* parent, const char* name, + const KoPageLayout& layout, + const KoHeadFoot& headfoot, + const KoColumns& columns, + const KoKWHeaderFooter& kwheadfoot, + int tabs, KoUnit::Unit unit ); + + /** + * Destructor. + */ + ~KoPageLayoutDia(); + + /** + * Show page layout dialog. + * See constructor for documentation on the parameters + */ + static bool pageLayout( KoPageLayout&, KoHeadFoot&, int tabs, KoUnit::Unit& unit, QWidget* parent = 0 ); + + /** + * Show page layout dialog. + * See constructor for documentation on the parameters + */ + static bool pageLayout( KoPageLayout&, KoHeadFoot&, KoColumns&, KoKWHeaderFooter&, int tabs, KoUnit::Unit& unit, QWidget* parent = 0 ); + /** + * Retrieves a standard page layout. + * Deprecated: better use KoPageLayout::standardLayout() + */ + static KDE_DEPRECATED KoPageLayout standardLayout(); + + /** + * Returns the layout + */ + const KoPageLayout& layout() const { return m_layout; } + + /** + * Returns the header and footer information + */ + KoHeadFoot headFoot() const; + + /** + * Returns the unit + */ + KoUnit::Unit unit() const { return m_unit; } + +private: + const KoColumns& columns() { return m_column; } + const KoKWHeaderFooter& headerFooter(); + + // setup tabs + void setupTab1( bool enableBorders ); + void setupTab2( const KoHeadFoot& hf ); + void setupTab3(); + void setupTab4( const KoKWHeaderFooter kwhf ); + + // dialog objects + QLineEdit *eHeadLeft; + QLineEdit *eHeadMid; + QLineEdit *eHeadRight; + QLineEdit *eFootLeft; + QLineEdit *eFootMid; + QLineEdit *eFootRight; + + // layout + KoPageLayout m_layout; + KoColumns m_column; + + KoUnit::Unit m_unit; + + int flags; + +protected slots: + virtual void slotOk(); + +private slots: + void sizeUpdated(KoPageLayout &layout); + void columnsUpdated(KoColumns &columns); + +private: + KoPageLayoutSize *m_pageSizeTab; + KoPageLayoutColumns *m_columnsTab; + KoPageLayoutHeader *m_headerTab; + KoPageLayoutDiaPrivate *d; +}; + +#endif diff --git a/kexi/3rdparty/kolibs/koUnit.cc b/kexi/3rdparty/kolibs/koUnit.cc new file mode 100644 index 00000000..6c19a29f --- /dev/null +++ b/kexi/3rdparty/kolibs/koUnit.cc @@ -0,0 +1,219 @@ +/* This file is part of the KDE project + Copyright (C) 2001 David Faure <faure@kde.org> + Copyright (C) 2004, Nicolas GOUTTE <goutte@kde.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. +*/ + +//#include <KoGlobal.h> +#include "KoUnit.h" +#ifndef SIMPLE_KOLIBS +# include <KoXmlWriter.h> +#endif + +#include <klocale.h> +#include <kglobal.h> +#include <kdebug.h> + +#include <qregexp.h> +#include <qdom.h> + +QStringList KoUnit::listOfUnitName() +{ + QStringList lst; + for ( uint i = 0 ; i <= KoUnit::U_LASTUNIT ; ++i ) + { + KoUnit::Unit unit = static_cast<KoUnit::Unit>( i ); + lst.append( KoUnit::unitDescription( unit ) ); + } + return lst; +} + +QString KoUnit::unitDescription( Unit _unit ) +{ + switch ( _unit ) + { + case KoUnit::U_MM: + return i18n("Millimeters (mm)"); + case KoUnit::U_CM: + return i18n("Centimeters (cm)"); + case KoUnit::U_DM: + return i18n("Decimeters (dm)"); + case KoUnit::U_INCH: + return i18n("Inches (in)"); + case KoUnit::U_PI: + return i18n("Pica (pi)"); + case KoUnit::U_DD: + return i18n("Didot (dd)"); + case KoUnit::U_CC: + return i18n("Cicero (cc)"); + case KoUnit::U_PT: + return i18n("Points (pt)" ); + default: + return i18n("Error!"); + } +} + +double KoUnit::toUserValue( double ptValue, Unit unit ) +{ + switch ( unit ) { + case U_MM: + return toMM( ptValue ); + case U_CM: + return toCM( ptValue ); + case U_DM: + return toDM( ptValue ); + case U_INCH: + return toInch( ptValue ); + case U_PI: + return toPI( ptValue ); + case U_DD: + return toDD( ptValue ); + case U_CC: + return toCC( ptValue ); + case U_PT: + default: + return toPoint( ptValue ); + } +} + +double KoUnit::ptToUnit( const double ptValue, const Unit unit ) +{ + switch ( unit ) + { + case U_MM: + return POINT_TO_MM( ptValue ); + case U_CM: + return POINT_TO_CM( ptValue ); + case U_DM: + return POINT_TO_DM( ptValue ); + case U_INCH: + return POINT_TO_INCH( ptValue ); + case U_PI: + return POINT_TO_PI( ptValue ); + case U_DD: + return POINT_TO_DD( ptValue ); + case U_CC: + return POINT_TO_CC( ptValue ); + case U_PT: + default: + return ptValue; + } +} + +QString KoUnit::toUserStringValue( double ptValue, Unit unit ) +{ + return KGlobal::locale()->formatNumber( toUserValue( ptValue, unit ) ); +} + +double KoUnit::fromUserValue( double value, Unit unit ) +{ + switch ( unit ) { + case U_MM: + return MM_TO_POINT( value ); + case U_CM: + return CM_TO_POINT( value ); + case U_DM: + return DM_TO_POINT( value ); + case U_INCH: + return INCH_TO_POINT( value ); + case U_PI: + return PI_TO_POINT( value ); + case U_DD: + return DD_TO_POINT( value ); + case U_CC: + return CC_TO_POINT( value ); + case U_PT: + default: + return value; + } +} + +double KoUnit::fromUserValue( const QString& value, Unit unit, bool* ok ) +{ + return fromUserValue( KGlobal::locale()->readNumber( value, ok ), unit ); +} + +double KoUnit::parseValue( QString value, double defaultVal ) +{ + value.simplifyWhiteSpace(); + value.remove( ' ' ); + + if( value.isEmpty() ) + return defaultVal; + + int index = value.find( QRegExp( "[a-z]+$" ) ); + if ( index == -1 ) + return value.toDouble(); + + QString unit = value.mid( index ); + value.truncate ( index ); + double val = value.toDouble(); + + if ( unit == "pt" ) + return val; + + bool ok; + Unit u = KoUnit::unit( unit, &ok ); + if( ok ) + return fromUserValue( val, u ); + + if( unit == "m" ) + return fromUserValue( val * 10.0, U_DM ); + else if( unit == "km" ) + return fromUserValue( val * 10000.0, U_DM ); + kdWarning() << "KoUnit::parseValue: Unit " << unit << " is not supported, please report." << endl; + + // TODO : add support for mi/ft ? + return defaultVal; +} + +KoUnit::Unit KoUnit::unit( const QString &_unitName, bool* ok ) +{ + if ( ok ) + *ok = true; + if ( _unitName == QString::fromLatin1( "mm" ) ) return U_MM; + if ( _unitName == QString::fromLatin1( "cm" ) ) return U_CM; + if ( _unitName == QString::fromLatin1( "dm" ) ) return U_DM; + if ( _unitName == QString::fromLatin1( "in" ) + || _unitName == QString::fromLatin1("inch") /*compat*/ ) return U_INCH; + if ( _unitName == QString::fromLatin1( "pi" ) ) return U_PI; + if ( _unitName == QString::fromLatin1( "dd" ) ) return U_DD; + if ( _unitName == QString::fromLatin1( "cc" ) ) return U_CC; + if ( _unitName == QString::fromLatin1( "pt" ) ) return U_PT; + if ( ok ) + *ok = false; + return U_PT; +} + +QString KoUnit::unitName( Unit _unit ) +{ + if ( _unit == U_MM ) return QString::fromLatin1( "mm" ); + if ( _unit == U_CM ) return QString::fromLatin1( "cm" ); + if ( _unit == U_DM ) return QString::fromLatin1( "dm" ); + if ( _unit == U_INCH ) return QString::fromLatin1( "in" ); + if ( _unit == U_PI ) return QString::fromLatin1( "pi" ); + if ( _unit == U_DD ) return QString::fromLatin1( "dd" ); + if ( _unit == U_CC ) return QString::fromLatin1( "cc" ); + return QString::fromLatin1( "pt" ); +} + +#ifndef SIMPLE_KOLIBS +void KoUnit::saveOasis(KoXmlWriter* settingsWriter, Unit _unit) +{ + settingsWriter->addConfigItem( "unit", unitName(_unit) ); +} +#endif diff --git a/kexi/3rdparty/kolibs/koUnit.h b/kexi/3rdparty/kolibs/koUnit.h new file mode 100644 index 00000000..86f749d6 --- /dev/null +++ b/kexi/3rdparty/kolibs/koUnit.h @@ -0,0 +1,177 @@ +/* This file is part of the KDE project + Copyright (C) 1998, 1999 Reginald Stadlbauer <reggie@kde.org>, Torben Weis <weis@kde.org> + Copyright (C) 2004, Nicolas GOUTTE <goutte@kde.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. +*/ + +#ifndef kounit_h +#define kounit_h +#include <qstring.h> +#include <qstringlist.h> +#include <math.h> // for floor +#include <koffice_export.h> + +class KoXmlWriter; +class QDomElement; + +// 1 inch ^= 72 pt +// 1 inch ^= 25.399956 mm (-pedantic ;p) +// 1 pt = 1/12 pi +// 1 pt ^= 0.0077880997 cc +// 1 cc = 12 dd +// Note: I don't use division but multiplication with the inverse value +// because it's faster ;p (Werner) +#define POINT_TO_MM(px) ((px)*0.352777167) +#define MM_TO_POINT(mm) ((mm)*2.83465058) +#define POINT_TO_CM(px) ((px)*0.0352777167) +#define CM_TO_POINT(cm) ((cm)*28.3465058) +#define POINT_TO_DM(px) ((px)*0.00352777167) +#define DM_TO_POINT(dm) ((dm)*283.465058) +#define POINT_TO_INCH(px) ((px)*0.01388888888889) +#define INCH_TO_POINT(inch) ((inch)*72.0) +#define MM_TO_INCH(mm) ((mm)*0.039370147) +#define INCH_TO_MM(inch) ((inch)*25.399956) +#define POINT_TO_PI(px)((px)*0.083333333) +#define POINT_TO_DD(px)((px)*0.006490083) +#define POINT_TO_CC(px)((px)*0.077880997) +#define PI_TO_POINT(pi)((pi)*12) +#define DD_TO_POINT(dd)((dd)*154.08124) +#define CC_TO_POINT(cc)((cc)*12.840103) +/** + * %KOffice stores everything in pt (using "double") internally. + * When displaying a value to the user, the value is converted to the user's unit + * of choice, and rounded to a reasonable precision to avoid 0.999999 + */ +class KOFFICECORE_EXPORT KoUnit +{ +public: + /** Length units supported by KOffice. */ + enum Unit { + U_MM = 0, + U_PT = 1, + U_INCH = 2, + U_CM = 3, + U_DM = 4, + U_PI = 5, // pica + U_DD = 6, // didot + U_CC = 7, // cicero + U_LASTUNIT = U_CC // update when adding a new unit + // when adding a new unit, make sure to implement support for it in koRuler too + }; + + /// Prepare ptValue to be displayed in pt + static double toPoint( double ptValue ) { + // No conversion, only rounding (to 0.001 precision) + return floor( ptValue * 1000.0 ) / 1000.0; + } + + /// Prepare ptValue to be displayed in mm + static double toMM( double ptValue ) { + // "mm" values are rounded to 0.0001 millimeters + return floor( POINT_TO_MM( ptValue ) * 10000.0 ) / 10000.0; + } + + /// Prepare ptValue to be displayed in cm + static double toCM( double ptValue ) { + return floor( POINT_TO_CM( ptValue ) * 10000.0 ) / 10000.0; + } + + /// Prepare ptValue to be displayed in dm + static double toDM( double ptValue ) { + return floor( POINT_TO_DM( ptValue ) * 10000.0 ) / 10000.0; + } + + /// Prepare ptValue to be displayed in inch + static double toInch( double ptValue ) { + // "in" values are rounded to 0.00001 inches + return floor( POINT_TO_INCH( ptValue ) * 100000.0 ) / 100000.0; + } + + /// Prepare ptValue to be displayed in pica + static double toPI( double ptValue ) { + // "pi" values are rounded to 0.00001 inches + return floor( POINT_TO_PI( ptValue ) * 100000.0 ) / 100000.0; + } + + /// Prepare ptValue to be displayed in didot + static double toDD( double ptValue ) { + // "dd" values are rounded to 0.00001 inches + return floor( POINT_TO_DD( ptValue ) * 100000.0 ) / 100000.0; + } + + /// Prepare ptValue to be displayed in cicero + static double toCC( double ptValue ) { + // "cc" values are rounded to 0.00001 inches + return floor( POINT_TO_CC( ptValue ) * 100000.0 ) / 100000.0; + } + + /** + * This method is the one to use to display a value in a dialog + * \return the value @p ptValue converted to @p unit and rounded, ready to be displayed + * Old name: ptToUnit + */ + static double toUserValue( double ptValue, Unit unit ); + + /** + * Convert the value @p ptValue to a given unit @p unit + * Unlike KoUnit::ptToUnit the return value remains unrounded, so that it can be used in complex calculation + * \return the converted value + * Old name: ptToUnitUnrounded + */ + static double ptToUnit( const double ptValue, const Unit unit ); + + /// This method is the one to use to display a value in a dialog + /// @return the value @p ptValue converted to @p unit and rounded, ready to be displayed + /// Old name: userValue + static QString toUserStringValue( double ptValue, Unit unit ); + + /// This method is the one to use to read a value from a dialog + /// @return the value in @p unit, converted to points for internal use + /// Old name: ptFromUnit + static double fromUserValue( double value, Unit unit ); + + /// This method is the one to use to read a value from a dialog + /// @param value value entered by the user + /// @param unit unit type selected by the user + /// @param ok if set, the pointed bool is set to true if the value could be + /// converted to a double, and to false otherwise. + /// @return the value in @p unit, converted to points for internal use + static double fromUserValue( const QString& value, Unit unit, bool* ok = 0 ); + + /// Convert a unit name into a Unit enum + /// @param _unitName name to convert + /// @param ok if set, it will be true if the unit was known, false if unknown + static Unit unit( const QString &_unitName, bool* ok = 0 ); + /// Get the name of a unit + static QString unitName( Unit _unit ); + /// Get the full (translated) description of a unit + static QString unitDescription( Unit _unit ); + static QStringList listOfUnitName(); + + /// parse common %KOffice and OO values, like "10cm", "5mm" to pt + static double parseValue( QString value, double defaultVal = 0.0 ); + // Note: the above method doesn't take a const ref, since it modifies the arg. + +#ifndef SIMPLE_KOLIBS + /// Save a unit in OASIS format + static void saveOasis(KoXmlWriter* settingsWriter, Unit _unit); +#endif + +}; + + +#endif diff --git a/kexi/3rdparty/kolibs/koUnitWidgets.cc b/kexi/3rdparty/kolibs/koUnitWidgets.cc new file mode 100644 index 00000000..0472caf5 --- /dev/null +++ b/kexi/3rdparty/kolibs/koUnitWidgets.cc @@ -0,0 +1,454 @@ +/* This file is part of the KDE project + Copyright (C) 2002, Rob Buis(buis@kde.org) + Copyright (C) 2004, Nicolas GOUTTE <goutte@kde.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. +*/ + +#include "koUnitWidgets.moc" +#include <kdebug.h> +#include <kglobal.h> +#include <klocale.h> +#include <qpushbutton.h> +#include <qlayout.h> + + +// ---------------------------------------------------------------- +// Support classes + + +KoUnitDoubleValidator::KoUnitDoubleValidator( KoUnitDoubleBase *base, QObject *parent, const char *name ) +: KDoubleValidator( parent, name ), m_base( base ) +{ +} + +QValidator::State +KoUnitDoubleValidator::validate( QString &s, int &pos ) const +{ + + kdDebug(30004) << "KoUnitDoubleValidator::validate : " << s << " at " << pos << endl; + QValidator::State result = Acceptable; + + QRegExp regexp ("([ a-zA-Z]+)$"); // Letters or spaces at end + const int res = regexp.search( s ); + + if ( res == -1 ) + { + // Nothing like an unit? The user is probably editing the unit + kdDebug(30004) << "Intermediate (no unit)" << endl; + return Intermediate; + } + + // ### TODO: are all the QString::stripWhiteSpace really necessary? + const QString number ( s.left( res ).stripWhiteSpace() ); + const QString unitName ( regexp.cap( 1 ).stripWhiteSpace().lower() ); + + kdDebug(30004) << "Split:" << number << ":" << unitName << ":" << endl; + + bool ok = false; + const double value = m_base->toDouble( number, &ok ); + double newVal = 0.0; + if( ok ) + { + KoUnit::Unit unit = KoUnit::unit( unitName, &ok ); + if ( ok ) + newVal = KoUnit::fromUserValue( value, unit ); + else + { + // Probably the user is trying to edit the unit + kdDebug(30004) << "Intermediate (unknown unit)" << endl; + return Intermediate; + } + } + else + { + kdWarning(30004) << "Not a number: " << number << endl; + return Invalid; + } + + newVal = KoUnit::ptToUnit( newVal, m_base->m_unit ); + + s = m_base->getVisibleText( newVal ); + + return result; +} + + +QString KoUnitDoubleBase::getVisibleText( double value ) const +{ + const QString num ( QString( "%1%2").arg( KGlobal::locale()->formatNumber( value, m_precision ), KoUnit::unitName( m_unit ) ) ); + kdDebug(30004) << "getVisibleText: " << QString::number( value, 'f', 12 ) << " => " << num << endl; + return num; +} + +double KoUnitDoubleBase::toDouble( const QString& str, bool* ok ) const +{ + QString str2( str ); + /* KLocale::readNumber wants the thousand separator exactly at 1000. + But when editing, it might be anywhere. So we need to remove it. */ + const QString sep( KGlobal::locale()->thousandsSeparator() ); + if ( !sep.isEmpty() ) + str2.remove( sep ); + str2.remove( KoUnit::unitName( m_unit ) ); + const double dbl = KGlobal::locale()->readNumber( str2, ok ); + if ( ok ) + kdDebug(30004) << "toDouble:" << str << ": => :" << str2 << ": => " << QString::number( dbl, 'f', 12 ) << endl; + else + kdWarning(30004) << "toDouble error:" << str << ": => :" << str2 << ":" << endl; + return dbl; +} + + +// ---------------------------------------------------------------- +// Widget classes + + +KoUnitDoubleSpinBox::KoUnitDoubleSpinBox( QWidget *parent, const char *name ) + : KDoubleSpinBox( parent, name ), KoUnitDoubleBase( KoUnit::U_PT, 2 ) + , m_lowerInPoints( -9999 ) + , m_upperInPoints( 9999 ) + , m_stepInPoints( 1 ) +{ + KDoubleSpinBox::setPrecision( 2 ); + m_validator = new KoUnitDoubleValidator( this, this ); + QSpinBox::setValidator( m_validator ); + setAcceptLocalizedNumbers( true ); + setUnit( KoUnit::U_PT ); + + connect(this, SIGNAL(valueChanged( double )), SLOT(privateValueChanged())); +} + + +KoUnitDoubleSpinBox::KoUnitDoubleSpinBox( QWidget *parent, + double lower, double upper, + double step, + double value, + KoUnit::Unit unit, + unsigned int precision, + const char *name ) + : KDoubleSpinBox( lower, upper, step, value, precision, parent, name ), + KoUnitDoubleBase( unit, precision ), + m_lowerInPoints( lower ), m_upperInPoints( upper ), m_stepInPoints( step ) +{ + m_unit = KoUnit::U_PT; + m_validator = new KoUnitDoubleValidator( this, this ); + QSpinBox::setValidator( m_validator ); + setAcceptLocalizedNumbers( true ); + setUnit( unit ); + changeValue( value ); + setLineStep( 0.5 ); + + connect(this, SIGNAL(valueChanged( double )), SLOT(privateValueChanged())); +} + +void +KoUnitDoubleSpinBox::changeValue( double val ) +{ + KDoubleSpinBox::setValue( KoUnit::toUserValue( val, m_unit ) ); + // TODO: emit valueChanged ONLY if the value was out-of-bounds + // This will allow the 'user' dialog to set a dirty bool and ensure + // a proper value is getting saved. +} + +void KoUnitDoubleSpinBox::privateValueChanged() { + emit valueChangedPt( value () ); +} + +void +KoUnitDoubleSpinBox::setUnit( KoUnit::Unit unit ) +{ + double oldvalue = KoUnit::fromUserValue( KDoubleSpinBox::value(), m_unit ); + KDoubleSpinBox::setMinValue( KoUnit::toUserValue( m_lowerInPoints, unit ) ); + KDoubleSpinBox::setMaxValue( KoUnit::toUserValue( m_upperInPoints, unit ) ); + KDoubleSpinBox::setLineStep( KoUnit::toUserValue( m_stepInPoints, unit ) ); + KDoubleSpinBox::setValue( KoUnit::ptToUnit( oldvalue, unit ) ); + m_unit = unit; + setSuffix( KoUnit::unitName( unit ).prepend( ' ' ) ); +} + +double KoUnitDoubleSpinBox::value( void ) const +{ + return KoUnit::fromUserValue( KDoubleSpinBox::value(), m_unit ); +} + +void KoUnitDoubleSpinBox::setMinValue( double min ) +{ + m_lowerInPoints = min; + KDoubleSpinBox::setMinValue( KoUnit::toUserValue( m_lowerInPoints, m_unit ) ); +} + +void KoUnitDoubleSpinBox::setMaxValue( double max ) +{ + m_upperInPoints = max; + KDoubleSpinBox::setMaxValue( KoUnit::toUserValue( m_upperInPoints, m_unit ) ); +} + +void KoUnitDoubleSpinBox::setLineStep( double step ) +{ + m_stepInPoints = KoUnit::toUserValue(step, KoUnit::U_PT ); + KDoubleSpinBox::setLineStep( step ); +} + +void KoUnitDoubleSpinBox::setLineStepPt( double step ) +{ + m_stepInPoints = step; + KDoubleSpinBox::setLineStep( KoUnit::toUserValue( m_stepInPoints, m_unit ) ); +} + +void KoUnitDoubleSpinBox::setMinMaxStep( double min, double max, double step ) +{ + setMinValue( min ); + setMaxValue( max ); + setLineStepPt( step ); +} + +// ---------------------------------------------------------------- + + +KoUnitDoubleLineEdit::KoUnitDoubleLineEdit( QWidget *parent, const char *name ) + : KLineEdit( parent, name ), KoUnitDoubleBase( KoUnit::U_PT, 2 ), m_value( 0.0 ), m_lower( 0.0 ), m_upper( 9999.99 ), + m_lowerInPoints( 0.0 ), m_upperInPoints( 9999.99 ) +{ + setAlignment( Qt::AlignRight ); + m_validator = new KoUnitDoubleValidator( this, this ); + setValidator( m_validator ); + setUnit( KoUnit::U_PT ); + changeValue( KoUnit::ptToUnit( 0.0, KoUnit::U_PT ) ); +} + +KoUnitDoubleLineEdit::KoUnitDoubleLineEdit( QWidget *parent, double lower, double upper, double value, KoUnit::Unit unit, + unsigned int precision, const char *name ) + : KLineEdit( parent, name ), KoUnitDoubleBase( unit, precision ), m_value( value ), m_lower( lower ), m_upper( upper ), + m_lowerInPoints( lower ), m_upperInPoints( upper ) +{ + setAlignment( Qt::AlignRight ); + m_validator = new KoUnitDoubleValidator( this, this ); + setValidator( m_validator ); + setUnit( unit ); + changeValue( KoUnit::ptToUnit( value, unit ) ); +} + +void +KoUnitDoubleLineEdit::changeValue( double value ) +{ + m_value = value < m_lower ? m_lower : ( value > m_upper ? m_upper : value ); + setText( getVisibleText( m_value ) ); +} + +void +KoUnitDoubleLineEdit::setUnit( KoUnit::Unit unit ) +{ + KoUnit::Unit old = m_unit; + m_unit = unit; + m_lower = KoUnit::ptToUnit( m_lowerInPoints, unit ); + m_upper = KoUnit::ptToUnit( m_upperInPoints, unit ); + changeValue( KoUnit::ptToUnit( KoUnit::fromUserValue( m_value, old ), unit ) ); +} + +bool +KoUnitDoubleLineEdit::eventFilter( QObject* o, QEvent* ev ) +{ +#if 0 + if( ev->type() == QEvent::FocusOut || ev->type() == QEvent::Leave || ev->type() == QEvent::Hide ) + { + bool ok; + double value = toDouble( text(), &ok ); + changeValue( value ); + return false; + } + else +#endif + return QLineEdit::eventFilter( o, ev ); +} + +double KoUnitDoubleLineEdit::value( void ) const +{ + return KoUnit::fromUserValue( m_value, m_unit ); +} + + +// ---------------------------------------------------------------- + + +KoUnitDoubleComboBox::KoUnitDoubleComboBox( QWidget *parent, const char *name ) + : KComboBox( true, parent, name ), KoUnitDoubleBase( KoUnit::U_PT, 2 ), m_value( 0.0 ), m_lower( 0.0 ), m_upper( 9999.99 ), m_lowerInPoints( 0.0 ), m_upperInPoints( 9999.99 ) +{ + lineEdit()->setAlignment( Qt::AlignRight ); + m_validator = new KoUnitDoubleValidator( this, this ); + lineEdit()->setValidator( m_validator ); + setUnit( KoUnit::U_PT ); + changeValue( KoUnit::ptToUnit( 0.0, KoUnit::U_PT ) ); + connect( this, SIGNAL( activated( int ) ), this, SLOT( slotActivated( int ) ) ); +} + +KoUnitDoubleComboBox::KoUnitDoubleComboBox( QWidget *parent, double lower, double upper, double value, KoUnit::Unit unit, + unsigned int precision, const char *name ) + : KComboBox( true, parent, name ), KoUnitDoubleBase( unit, precision ), m_value( value ), m_lower( lower ), m_upper( upper ), + m_lowerInPoints( lower ), m_upperInPoints( upper ) +{ + lineEdit()->setAlignment( Qt::AlignRight ); + m_validator = new KoUnitDoubleValidator( this, this ); + lineEdit()->setValidator( m_validator ); + setUnit( unit ); + changeValue( KoUnit::ptToUnit( value, unit ) ); + connect( this, SIGNAL( activated( int ) ), this, SLOT( slotActivated( int ) ) ); +} + +void +KoUnitDoubleComboBox::changeValue( double value ) +{ + QString oldLabel = lineEdit()->text(); + updateValue( value ); + if( lineEdit()->text() != oldLabel ) + emit valueChanged( m_value ); +} + +void +KoUnitDoubleComboBox::updateValue( double value ) +{ + m_value = value < m_lower ? m_lower : ( value > m_upper ? m_upper : value ); + lineEdit()->setText( getVisibleText( m_value ) ); +} + +void +KoUnitDoubleComboBox::insertItem( double value, int index ) +{ + KComboBox::insertItem( getVisibleText( value ), index ); +} + +void +KoUnitDoubleComboBox::slotActivated( int index ) +{ + double oldvalue = m_value; + bool ok; + double value = toDouble( text( index ), &ok ); + m_value = value < m_lower ? m_lower : ( value > m_upper ? m_upper : value ); + if( m_value != oldvalue ) + emit valueChanged( m_value ); +} + +void +KoUnitDoubleComboBox::setUnit( KoUnit::Unit unit ) +{ + KoUnit::Unit old = m_unit; + m_unit = unit; + m_lower = KoUnit::ptToUnit( m_lowerInPoints, unit ); + m_upper = KoUnit::ptToUnit( m_upperInPoints, unit ); + changeValue( KoUnit::ptToUnit( KoUnit::fromUserValue( m_value, old ), unit ) ); +} + +bool +KoUnitDoubleComboBox::eventFilter( QObject* o, QEvent* ev ) +{ +#if 0 + if( ev->type() == QEvent::FocusOut || ev->type() == QEvent::Leave || ev->type() == QEvent::Hide ) + { + bool ok; + double value = toDouble( lineEdit()->text(), &ok ); + changeValue( value ); + return false; + } + else +#endif + return QComboBox::eventFilter( o, ev ); +} + +double KoUnitDoubleComboBox::value( void ) const +{ + return KoUnit::fromUserValue( m_value, m_unit ); +} + + +// ---------------------------------------------------------------- + + +KoUnitDoubleSpinComboBox::KoUnitDoubleSpinComboBox( QWidget *parent, const char *name ) + : QWidget( parent ), m_step( 1.0 ) +{ + QGridLayout *layout = new QGridLayout( this, 2, 3 ); + //layout->setMargin( 2 ); + QPushButton *up = new QPushButton( "+", this ); + //up->setFlat( true ); + up->setMaximumHeight( 15 ); + up->setMaximumWidth( 15 ); + layout->addWidget( up, 0, 0 ); + connect( up, SIGNAL( clicked() ), this, SLOT( slotUpClicked() ) ); + + QPushButton *down = new QPushButton( "-", this ); + down->setMaximumHeight( 15 ); + down->setMaximumWidth( 15 ); + layout->addWidget( down, 1, 0 ); + connect( down, SIGNAL( clicked() ), this, SLOT( slotDownClicked() ) ); + + m_combo = new KoUnitDoubleComboBox( this, KoUnit::ptToUnit( 0.0, KoUnit::U_PT ), KoUnit::ptToUnit( 9999.99, KoUnit::U_PT ), 0.0, KoUnit::U_PT, 2, name ); + connect( m_combo, SIGNAL( valueChanged( double ) ), this, SIGNAL( valueChanged( double ) ) ); + layout->addMultiCellWidget( m_combo, 0, 1, 2, 2 ); +} + +KoUnitDoubleSpinComboBox::KoUnitDoubleSpinComboBox( QWidget *parent, double lower, double upper, double step, double value, + KoUnit::Unit unit, unsigned int precision, const char *name ) + : QWidget( parent ), m_step( step )//, m_lowerInPoints( lower ), m_upperInPoints( upper ) +{ + QGridLayout *layout = new QGridLayout( this, 2, 3 ); + //layout->setMargin( 2 ); + QPushButton *up = new QPushButton( "+", this ); + //up->setFlat( true ); + up->setMaximumHeight( 15 ); + up->setMaximumWidth( 15 ); + layout->addWidget( up, 0, 0 ); + connect( up, SIGNAL( clicked() ), this, SLOT( slotUpClicked() ) ); + + QPushButton *down = new QPushButton( "-", this ); + down->setMaximumHeight( 15 ); + down->setMaximumWidth( 15 ); + layout->addWidget( down, 1, 0 ); + connect( down, SIGNAL( clicked() ), this, SLOT( slotDownClicked() ) ); + + m_combo = new KoUnitDoubleComboBox( this, KoUnit::ptToUnit( lower, unit ), KoUnit::ptToUnit( upper, unit ), value, unit, precision, name ); + connect( m_combo, SIGNAL( valueChanged( double ) ), this, SIGNAL( valueChanged( double ) ) ); + layout->addMultiCellWidget( m_combo, 0, 1, 2, 2 ); +} + +void +KoUnitDoubleSpinComboBox::slotUpClicked() +{ + m_combo->changeValue( m_combo->value() + m_step ); +} + +void +KoUnitDoubleSpinComboBox::slotDownClicked() +{ + m_combo->changeValue( m_combo->value() - m_step ); +} + +void +KoUnitDoubleSpinComboBox::insertItem( double value, int index ) +{ + m_combo->insertItem( value, index ); +} + +void +KoUnitDoubleSpinComboBox::updateValue( double value ) +{ + m_combo->updateValue( value ); +} + +double +KoUnitDoubleSpinComboBox::value() const +{ + return m_combo->value(); +} + diff --git a/kexi/3rdparty/kolibs/koUnitWidgets.h b/kexi/3rdparty/kolibs/koUnitWidgets.h new file mode 100644 index 00000000..957b1b36 --- /dev/null +++ b/kexi/3rdparty/kolibs/koUnitWidgets.h @@ -0,0 +1,246 @@ +/* This file is part of the KDE project + Copyright (C) 2002, Rob Buis(buis@kde.org) + Copyright (C) 2004, Nicolas GOUTTE <goutte@kde.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. +*/ + +#ifndef __KOUNITWIDGETS_H__ +#define __KOUNITWIDGETS_H__ + +#include <knuminput.h> +#include <knumvalidator.h> +#include <klineedit.h> +#include <kcombobox.h> +#include <KoUnit.h> +#include <koffice_export.h> + + +// ---------------------------------------------------------------- +// Support classes + + +class KoUnitDoubleBase; + +// ### TODO: put it out of the public header file (if possible) +/** + * Validator for the unit widget classes + * \internal + * \since 1.4 (change of behavior) + */ +class KOFFICEUI_EXPORT KoUnitDoubleValidator : public KDoubleValidator +{ +public: + KoUnitDoubleValidator( KoUnitDoubleBase *base, QObject *parent, const char *name = 0 ); + + virtual QValidator::State validate( QString &, int & ) const; + +private: + KoUnitDoubleBase *m_base; +}; + + +/** + * Base for the unit widgets + * \since 1.4 (change of behavior) + */ +class KOFFICEUI_EXPORT KoUnitDoubleBase +{ +public: + KoUnitDoubleBase( KoUnit::Unit unit, unsigned int precision ) : m_unit( unit ), m_precision( precision ) {} + virtual ~KoUnitDoubleBase() {} + + virtual void changeValue( double ) = 0; + virtual void setUnit( KoUnit::Unit = KoUnit::U_PT ) = 0; + + void setValueInUnit( double value, KoUnit::Unit unit ) + { + changeValue( KoUnit::ptToUnit( KoUnit::fromUserValue( value, unit ), m_unit ) ); + } + + void setPrecision( unsigned int precision ) { m_precision = precision; }; + +protected: + friend class KoUnitDoubleValidator; + /** + * Transform the double in a nice text, using locale symbols + * @param value the number as double + * @return the resulting string + */ + QString getVisibleText( double value ) const; + /** + * Transfrom a string into a double, while taking care of locale specific symbols. + * @param str the string to transform into a number + * @param ok true, if the conversion was succesful + * @return the value as double + */ + double toDouble( const QString& str, bool* ok ) const; + +protected: + KoUnitDoubleValidator *m_validator; + KoUnit::Unit m_unit; + unsigned int m_precision; +}; + + +// ---------------------------------------------------------------- +// Widget classes + + +/** + * Spin box for double precision numbers with unit display + * \since 1.4 (change of behavior) + */ +class KOFFICEUI_EXPORT KoUnitDoubleSpinBox : public KDoubleSpinBox, public KoUnitDoubleBase +{ + Q_OBJECT +public: + KoUnitDoubleSpinBox( QWidget *parent = 0L, const char *name = 0L ); + // lower, upper, step and value are in pt + KoUnitDoubleSpinBox( QWidget *parent, double lower, double upper, double step, double value = 0.0, + KoUnit::Unit unit = KoUnit::U_PT, unsigned int precision = 2, const char *name = 0 ); + // added so the class can be used in .ui files(by Tymoteusz Majewski, maju7@o2.pl) + virtual void changeValue( double ); + virtual void setUnit( KoUnit::Unit = KoUnit::U_PT ); + + /// @return the current value, converted in points + double value( void ) const; + + /// Set minimum value in points. + void setMinValue(double min); + + /// Set maximum value in points. + void setMaxValue(double max); + + /// Set step size in the current unit. + void setLineStep(double step); + + /// Set step size in points. + void setLineStepPt(double step); + + /// Set minimum, maximum value and the step size (all in points) (by Tymoteusz Majewski, maju7@o2.pl) + void setMinMaxStep( double min, double max, double step ); + +signals: + /// emitted like valueChanged in the parent, but this one emits the point value + void valueChangedPt( double ); + + +private: + double m_lowerInPoints; ///< lowest value in points + double m_upperInPoints; ///< highest value in points + double m_stepInPoints; ///< step in points + +private slots: + // exists to do emits for valueChangedPt + void privateValueChanged(); +}; + + +/** + * Line edit for double precision numbers with unit display + * \since 1.4 (change of behavior) + */ +class KOFFICEUI_EXPORT KoUnitDoubleLineEdit : public KLineEdit, public KoUnitDoubleBase +{ + Q_OBJECT +public: + KoUnitDoubleLineEdit( QWidget *parent = 0L, const char *name = 0L ); + KoUnitDoubleLineEdit( QWidget *parent, double lower, double upper, double value = 0.0, KoUnit::Unit unit = KoUnit::U_PT, unsigned int precision = 2, const char *name = 0 ); + + virtual void changeValue( double ); + virtual void setUnit( KoUnit::Unit = KoUnit::U_PT ); + + /// @return the current value, converted in points + double value( void ) const; + +protected: + bool eventFilter( QObject* obj, QEvent* ev ); + +private: + double m_value; + double m_lower; + double m_upper; + double m_lowerInPoints; ///< lowest value in points + double m_upperInPoints; ///< highest value in points +}; + +/** + * Combo box for double precision numbers with unit display + * \since 1.4 (change of behavior) + */ +class KOFFICEUI_EXPORT KoUnitDoubleComboBox : public KComboBox, public KoUnitDoubleBase +{ + Q_OBJECT +public: + KoUnitDoubleComboBox( QWidget *parent = 0L, const char *name = 0L ); + KoUnitDoubleComboBox( QWidget *parent, double lower, double upper, double value = 0.0, KoUnit::Unit unit = KoUnit::U_PT, unsigned int precision = 2, const char *name = 0 ); + + virtual void changeValue( double ); + void updateValue( double ); + virtual void setUnit( KoUnit::Unit = KoUnit::U_PT ); + + /// @return the current value, converted in points + double value( void ) const; + void insertItem( double, int index = -1 ); + +protected: + bool eventFilter( QObject* obj, QEvent* ev ); + +signals: + void valueChanged(double); + +private slots: + void slotActivated( int ); + +protected: + double m_value; + double m_lower; + double m_upper; + double m_lowerInPoints; ///< lowest value in points + double m_upperInPoints; ///< highest value in points +}; + +/** + * Combo box (with spin control) for double precision numbers with unit display + * \since 1.4 (change of behavior) + */ +class KOFFICEUI_EXPORT KoUnitDoubleSpinComboBox : public QWidget +{ + Q_OBJECT +public: + KoUnitDoubleSpinComboBox( QWidget *parent = 0L, const char *name = 0L ); + KoUnitDoubleSpinComboBox( QWidget *parent, double lower, double upper, double step, double value = 0.0, KoUnit::Unit unit = KoUnit::U_PT, unsigned int precision = 2, const char *name = 0 ); + + void insertItem( double, int index = -1 ); + void updateValue( double ); + /// @return the current value, converted in points + double value( void ) const; + +signals: + void valueChanged(double); + +private slots: + void slotUpClicked(); + void slotDownClicked(); + +private: + KoUnitDoubleComboBox *m_combo; + double m_step; +}; + +#endif + diff --git a/kexi/3rdparty/kolibs/koffice_export.h b/kexi/3rdparty/kolibs/koffice_export.h new file mode 100644 index 00000000..08b660ce --- /dev/null +++ b/kexi/3rdparty/kolibs/koffice_export.h @@ -0,0 +1,2 @@ + +/* private code: no need to export anything */ |