From 8b78a8791bc539bcffe7159f9d9714d577cb3d7d Mon Sep 17 00:00:00 2001 From: Michele Calgaro Date: Sun, 23 May 2021 20:48:35 +0900 Subject: Renaming of files in preparation for code style tools. Signed-off-by: Michele Calgaro --- kexi/3rdparty/kolibs/Makefile.am | 8 +- kexi/3rdparty/kolibs/koGlobal.cc | 202 -------------- kexi/3rdparty/kolibs/koGlobal.cpp | 202 ++++++++++++++ kexi/3rdparty/kolibs/koPageLayoutDia.cc | 402 --------------------------- kexi/3rdparty/kolibs/koPageLayoutDia.cpp | 402 +++++++++++++++++++++++++++ kexi/3rdparty/kolibs/koUnit.cc | 219 --------------- kexi/3rdparty/kolibs/koUnit.cpp | 219 +++++++++++++++ kexi/3rdparty/kolibs/koUnitWidgets.cc | 454 ------------------------------- kexi/3rdparty/kolibs/koUnitWidgets.cpp | 454 +++++++++++++++++++++++++++++++ 9 files changed, 1281 insertions(+), 1281 deletions(-) delete mode 100644 kexi/3rdparty/kolibs/koGlobal.cc create mode 100644 kexi/3rdparty/kolibs/koGlobal.cpp delete mode 100644 kexi/3rdparty/kolibs/koPageLayoutDia.cc create mode 100644 kexi/3rdparty/kolibs/koPageLayoutDia.cpp delete mode 100644 kexi/3rdparty/kolibs/koUnit.cc create mode 100644 kexi/3rdparty/kolibs/koUnit.cpp delete mode 100644 kexi/3rdparty/kolibs/koUnitWidgets.cc create mode 100644 kexi/3rdparty/kolibs/koUnitWidgets.cpp (limited to 'kexi/3rdparty/kolibs') diff --git a/kexi/3rdparty/kolibs/Makefile.am b/kexi/3rdparty/kolibs/Makefile.am index 05d3fbd3..c5b1cf7b 100644 --- a/kexi/3rdparty/kolibs/Makefile.am +++ b/kexi/3rdparty/kolibs/Makefile.am @@ -3,10 +3,10 @@ include $(top_srcdir)/kexi/Makefile.global noinst_LTLIBRARIES = libkexikolibs.la libkexikolibs_la_SOURCES = \ -koGlobal.cc \ -koUnit.cc \ -koUnitWidgets.cc \ -koPageLayoutDia.cc \ +koGlobal.cpp \ +koUnit.cpp \ +koUnitWidgets.cpp \ +koPageLayoutDia.cpp \ KoPageLayoutColumnsBase.ui \ KoPageLayoutColumns.cpp \ koPageLayout.cpp \ diff --git a/kexi/3rdparty/kolibs/koGlobal.cc b/kexi/3rdparty/kolibs/koGlobal.cc deleted file mode 100644 index a375327f..00000000 --- a/kexi/3rdparty/kolibs/koGlobal.cc +++ /dev/null @@ -1,202 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2001 David Faure - Copyright 2003 Nicolas GOUTTE - - 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 -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - - -KoGlobal* KoGlobal::s_global = 0L; -static KStaticDeleter 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 - TDEGlobal::locale()->insertCatalogue("koffice"); - - KImageIO::registerFormats(); - - // Tell TDEStandardDirs about the koffice prefix - TDEGlobal::dirs()->addPrefix(PREFIX); - - // Tell the iconloader about share/apps/koffice/icons - TDEGlobal::iconLoader()->addAppDir("koffice"); - - // Another way to get the DPI of the display would be TQPaintDeviceMetrics, - // 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 = TQPaintDevice::x11AppDpiX(); - m_dpiY = TQPaintDevice::x11AppDpiY(); -#else - m_dpiX = 75; - m_dpiY = 75; -#endif -} - -KoGlobal::~KoGlobal() -{ - delete m_kofficeConfig; -} - -TQFont KoGlobal::_defaultFont() -{ - TQFont font = TDEGlobalSettings::generalFont(); - // we have to use TQFontInfo, in case the font was specified with a pixel size - if ( font.pointSize() == -1 ) - { - // cache size into m_pointSize, since TQFontInfo loads the font -> slow - if ( m_pointSize == -1 ) - m_pointSize = TQFontInfo(font).pointSize(); - Q_ASSERT( m_pointSize != -1 ); - font.setPointSize( m_pointSize ); - } - //kdDebug()< seenLanguages; - const TQStringList langlist = config.groupList(); - for ( TQStringList::ConstIterator itall = langlist.begin(); - itall != langlist.end(); ++itall ) - { - const TQString tag = *itall; - config.setGroup( tag ); - const TQString name = config.readEntry("Name", tag); - // e.g. name is "French" and tag is "fr" - - // The TQMap 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 TQStringList translationList = TDEGlobal::dirs()->findAllResources("locale", - TQString::fromLatin1("*/entry.desktop")); - for ( TQStringList::ConstIterator it = translationList.begin(); - it != translationList.end(); ++it ) - { - // Extract the language tag from the directory name - TQString 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 TQString 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? -} - -TQString KoGlobal::tagOfLanguage( const TQString & _lang) -{ - const LanguageMap& map = self()->m_langMap; - TQMap::ConstIterator it = map.find( _lang ); - if ( it != map.end() ) - return *it; - return TQString(); -} - -TQString KoGlobal::languageFromTag( const TQString &langTag ) -{ - const LanguageMap& map = self()->m_langMap; - TQMap::ConstIterator it = map.begin(); - const TQMap::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; -} - -TDEConfig* KoGlobal::_kofficeConfig() -{ - if ( !m_kofficeConfig ) { - m_kofficeConfig = new TDEConfig( "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.cpp b/kexi/3rdparty/kolibs/koGlobal.cpp new file mode 100644 index 00000000..a375327f --- /dev/null +++ b/kexi/3rdparty/kolibs/koGlobal.cpp @@ -0,0 +1,202 @@ +/* This file is part of the KDE project + Copyright (C) 2001 David Faure + Copyright 2003 Nicolas GOUTTE + + 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +KoGlobal* KoGlobal::s_global = 0L; +static KStaticDeleter 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 + TDEGlobal::locale()->insertCatalogue("koffice"); + + KImageIO::registerFormats(); + + // Tell TDEStandardDirs about the koffice prefix + TDEGlobal::dirs()->addPrefix(PREFIX); + + // Tell the iconloader about share/apps/koffice/icons + TDEGlobal::iconLoader()->addAppDir("koffice"); + + // Another way to get the DPI of the display would be TQPaintDeviceMetrics, + // 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 = TQPaintDevice::x11AppDpiX(); + m_dpiY = TQPaintDevice::x11AppDpiY(); +#else + m_dpiX = 75; + m_dpiY = 75; +#endif +} + +KoGlobal::~KoGlobal() +{ + delete m_kofficeConfig; +} + +TQFont KoGlobal::_defaultFont() +{ + TQFont font = TDEGlobalSettings::generalFont(); + // we have to use TQFontInfo, in case the font was specified with a pixel size + if ( font.pointSize() == -1 ) + { + // cache size into m_pointSize, since TQFontInfo loads the font -> slow + if ( m_pointSize == -1 ) + m_pointSize = TQFontInfo(font).pointSize(); + Q_ASSERT( m_pointSize != -1 ); + font.setPointSize( m_pointSize ); + } + //kdDebug()< seenLanguages; + const TQStringList langlist = config.groupList(); + for ( TQStringList::ConstIterator itall = langlist.begin(); + itall != langlist.end(); ++itall ) + { + const TQString tag = *itall; + config.setGroup( tag ); + const TQString name = config.readEntry("Name", tag); + // e.g. name is "French" and tag is "fr" + + // The TQMap 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 TQStringList translationList = TDEGlobal::dirs()->findAllResources("locale", + TQString::fromLatin1("*/entry.desktop")); + for ( TQStringList::ConstIterator it = translationList.begin(); + it != translationList.end(); ++it ) + { + // Extract the language tag from the directory name + TQString 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 TQString 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? +} + +TQString KoGlobal::tagOfLanguage( const TQString & _lang) +{ + const LanguageMap& map = self()->m_langMap; + TQMap::ConstIterator it = map.find( _lang ); + if ( it != map.end() ) + return *it; + return TQString(); +} + +TQString KoGlobal::languageFromTag( const TQString &langTag ) +{ + const LanguageMap& map = self()->m_langMap; + TQMap::ConstIterator it = map.begin(); + const TQMap::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; +} + +TDEConfig* KoGlobal::_kofficeConfig() +{ + if ( !m_kofficeConfig ) { + m_kofficeConfig = new TDEConfig( "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/koPageLayoutDia.cc b/kexi/3rdparty/kolibs/koPageLayoutDia.cc deleted file mode 100644 index 2f0db91a..00000000 --- a/kexi/3rdparty/kolibs/koPageLayoutDia.cc +++ /dev/null @@ -1,402 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 1998, 1999 Reginald Stadlbauer - Copyright (C) 2005 Thomas Zander - - 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 -#include -#include -#include -#include -#include - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/******************************************************************/ -/* class KoPagePreview */ -/******************************************************************/ - -/*===================== constrcutor ==============================*/ -KoPagePreview::KoPagePreview( TQWidget* parent, const char *name, const KoPageLayout& layout ) - : TQGroupBox( 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(KoGlobal::dpiX()) ); - double resolutionY = POINT_TO_INCH( static_cast(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 = TQMIN( 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( TQPainter *painter ) -{ - double cw = m_textFrameWidth; - if(columns!=1) - cw/=static_cast(columns); - - painter->setBrush( white ); - painter->setPen( TQPen( black ) ); - - int x=static_cast( ( width() - m_pageWidth ) * 0.5 ); - int y=static_cast( ( height() - m_pageHeight ) * 0.5 ); - int w=static_cast(m_pageWidth); - int h=static_cast(m_pageHeight); - //painter->drawRect( x + 1, y + 1, w, h); - painter->drawRect( x, y, w, h ); - - painter->setBrush( TQBrush( 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(m_textFrameX) + static_cast(i * cw), - y + static_cast(m_textFrameY), static_cast(cw), - static_cast(m_textFrameHeight) ); -} - -/******************************************************************/ -/* class KoPageLayoutDia */ -/******************************************************************/ - -/*==================== constructor ===============================*/ -KoPageLayoutDia::KoPageLayoutDia( TQWidget* 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( TQ_StrongFocus ); - setFocus(); -} - -/*==================== constructor ===============================*/ -KoPageLayoutDia::KoPageLayoutDia( TQWidget* 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( TQ_StrongFocus ); - setFocus(); -} - -/*===================== destructor ===============================*/ -KoPageLayoutDia::~KoPageLayoutDia() -{ -} - -/*======================= show dialog ============================*/ -bool KoPageLayoutDia::pageLayout( KoPageLayout& layout, KoHeadFoot& hf, int tabs, KoUnit::Unit& unit, TQWidget* parent ) -{ - bool res = false; - KoPageLayoutDia *dlg = new KoPageLayoutDia( parent, "PageLayout", layout, hf, tabs, unit ); - - if ( dlg->exec() == TQDialog::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, TQWidget* parent ) -{ - bool res = false; - KoPageLayoutDia *dlg = new KoPageLayoutDia( parent, "PageLayout", layout, hf, columns, _kwhf, tabs, unit ); - - if ( dlg->exec() == TQDialog::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 ) -{ - TQWidget *tab1 = addPage(i18n( "Page Size && &Margins" )); - TQHBoxLayout *lay = new TQHBoxLayout(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, TQT_SIGNAL( propertyChange(KoPageLayout&)), - this, TQT_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 ) -{ - TQWidget *tab2 = addPage(i18n( "H&eader && Footer" )); - TQGridLayout *grid2 = new TQGridLayout( tab2, 7, 2, 0, KDialog::spacingHint() ); - - // ------------- header --------------- - TQGroupBox *gHead = new TQGroupBox( 0, Qt::Vertical, i18n( "Head Line" ), tab2 ); - gHead->layout()->setSpacing(KDialog::spacingHint()); - gHead->layout()->setMargin(KDialog::marginHint()); - TQGridLayout *headGrid = new TQGridLayout( gHead->layout(), 2, 3 ); - - TQLabel *lHeadLeft = new TQLabel( i18n( "Left:" ), gHead ); - headGrid->addWidget( lHeadLeft, 0, 0 ); - - eHeadLeft = new TQLineEdit( gHead ); - headGrid->addWidget( eHeadLeft, 1, 0 ); - eHeadLeft->setText( hf.headLeft ); - - TQLabel *lHeadMid = new TQLabel( i18n( "Mid:" ), gHead ); - headGrid->addWidget( lHeadMid, 0, 1 ); - - eHeadMid = new TQLineEdit( gHead ); - headGrid->addWidget( eHeadMid, 1, 1 ); - eHeadMid->setText( hf.headMid ); - - TQLabel *lHeadRight = new TQLabel( i18n( "Right:" ), gHead ); - headGrid->addWidget( lHeadRight, 0, 2 ); - - eHeadRight = new TQLineEdit( gHead ); - headGrid->addWidget( eHeadRight, 1, 2 ); - eHeadRight->setText( hf.headRight ); - - grid2->addMultiCellWidget( gHead, 0, 1, 0, 1 ); - - // ------------- footer --------------- - TQGroupBox *gFoot = new TQGroupBox( 0, Qt::Vertical, i18n( "Foot Line" ), tab2 ); - gFoot->layout()->setSpacing(KDialog::spacingHint()); - gFoot->layout()->setMargin(KDialog::marginHint()); - TQGridLayout *footGrid = new TQGridLayout( gFoot->layout(), 2, 3 ); - - TQLabel *lFootLeft = new TQLabel( i18n( "Left:" ), gFoot ); - footGrid->addWidget( lFootLeft, 0, 0 ); - - eFootLeft = new TQLineEdit( gFoot ); - footGrid->addWidget( eFootLeft, 1, 0 ); - eFootLeft->setText( hf.footLeft ); - - TQLabel *lFootMid = new TQLabel( i18n( "Mid:" ), gFoot ); - footGrid->addWidget( lFootMid, 0, 1 ); - - eFootMid = new TQLineEdit( gFoot ); - footGrid->addWidget( eFootMid, 1, 1 ); - eFootMid->setText( hf.footMid ); - - TQLabel *lFootRight = new TQLabel( i18n( "Right:" ), gFoot ); - footGrid->addWidget( lFootRight, 0, 2 ); - - eFootRight = new TQLineEdit( gFoot ); - footGrid->addWidget( eFootRight, 1, 2 ); - eFootRight->setText( hf.footRight ); - - grid2->addMultiCellWidget( gFoot, 2, 3, 0, 1 ); - - TQLabel *lMacros2 = new TQLabel( i18n( "You can insert several tags in the text:" ), tab2 ); - grid2->addMultiCellWidget( lMacros2, 4, 4, 0, 1 ); - - TQLabel *lMacros3 = new TQLabel( i18n("
  • <sheet> The sheet name
  • " - "
  • <page> The current page
  • " - "
  • <pages> The total number of pages
  • " - "
  • <name> The filename or URL
  • " - "
  • <file> The filename with complete path or the URL
"), tab2 ); - grid2->addMultiCellWidget( lMacros3, 5, 6, 0, 0, TQt::AlignTop ); - - TQLabel *lMacros4 = new TQLabel( i18n("
  • <time> The current time
  • " - "
  • <date> The current date
  • " - "
  • <author> Your full name
  • " - "
  • <org> Your organization
  • " - "
  • <email> Your email address
"), tab2 ); - grid2->addMultiCellWidget( lMacros4, 5, 6, 1, 1, TQt::AlignTop ); -} - -/*================================================================*/ -void KoPageLayoutDia::setupTab3() -{ - TQWidget *tab3 = addPage(i18n( "Col&umns" )); - TQHBoxLayout *lay = new TQHBoxLayout(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, TQT_SIGNAL( propertyChange(KoColumns&)), - this, TQT_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 ) -{ - TQWidget *tab4 = addPage(i18n( "H&eader && Footer" )); - TQHBoxLayout *lay = new TQHBoxLayout(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 diff --git a/kexi/3rdparty/kolibs/koPageLayoutDia.cpp b/kexi/3rdparty/kolibs/koPageLayoutDia.cpp new file mode 100644 index 00000000..2f0db91a --- /dev/null +++ b/kexi/3rdparty/kolibs/koPageLayoutDia.cpp @@ -0,0 +1,402 @@ +/* This file is part of the KDE project + Copyright (C) 1998, 1999 Reginald Stadlbauer + Copyright (C) 2005 Thomas Zander + + 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 +#include +#include +#include +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/******************************************************************/ +/* class KoPagePreview */ +/******************************************************************/ + +/*===================== constrcutor ==============================*/ +KoPagePreview::KoPagePreview( TQWidget* parent, const char *name, const KoPageLayout& layout ) + : TQGroupBox( 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(KoGlobal::dpiX()) ); + double resolutionY = POINT_TO_INCH( static_cast(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 = TQMIN( 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( TQPainter *painter ) +{ + double cw = m_textFrameWidth; + if(columns!=1) + cw/=static_cast(columns); + + painter->setBrush( white ); + painter->setPen( TQPen( black ) ); + + int x=static_cast( ( width() - m_pageWidth ) * 0.5 ); + int y=static_cast( ( height() - m_pageHeight ) * 0.5 ); + int w=static_cast(m_pageWidth); + int h=static_cast(m_pageHeight); + //painter->drawRect( x + 1, y + 1, w, h); + painter->drawRect( x, y, w, h ); + + painter->setBrush( TQBrush( 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(m_textFrameX) + static_cast(i * cw), + y + static_cast(m_textFrameY), static_cast(cw), + static_cast(m_textFrameHeight) ); +} + +/******************************************************************/ +/* class KoPageLayoutDia */ +/******************************************************************/ + +/*==================== constructor ===============================*/ +KoPageLayoutDia::KoPageLayoutDia( TQWidget* 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( TQ_StrongFocus ); + setFocus(); +} + +/*==================== constructor ===============================*/ +KoPageLayoutDia::KoPageLayoutDia( TQWidget* 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( TQ_StrongFocus ); + setFocus(); +} + +/*===================== destructor ===============================*/ +KoPageLayoutDia::~KoPageLayoutDia() +{ +} + +/*======================= show dialog ============================*/ +bool KoPageLayoutDia::pageLayout( KoPageLayout& layout, KoHeadFoot& hf, int tabs, KoUnit::Unit& unit, TQWidget* parent ) +{ + bool res = false; + KoPageLayoutDia *dlg = new KoPageLayoutDia( parent, "PageLayout", layout, hf, tabs, unit ); + + if ( dlg->exec() == TQDialog::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, TQWidget* parent ) +{ + bool res = false; + KoPageLayoutDia *dlg = new KoPageLayoutDia( parent, "PageLayout", layout, hf, columns, _kwhf, tabs, unit ); + + if ( dlg->exec() == TQDialog::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 ) +{ + TQWidget *tab1 = addPage(i18n( "Page Size && &Margins" )); + TQHBoxLayout *lay = new TQHBoxLayout(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, TQT_SIGNAL( propertyChange(KoPageLayout&)), + this, TQT_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 ) +{ + TQWidget *tab2 = addPage(i18n( "H&eader && Footer" )); + TQGridLayout *grid2 = new TQGridLayout( tab2, 7, 2, 0, KDialog::spacingHint() ); + + // ------------- header --------------- + TQGroupBox *gHead = new TQGroupBox( 0, Qt::Vertical, i18n( "Head Line" ), tab2 ); + gHead->layout()->setSpacing(KDialog::spacingHint()); + gHead->layout()->setMargin(KDialog::marginHint()); + TQGridLayout *headGrid = new TQGridLayout( gHead->layout(), 2, 3 ); + + TQLabel *lHeadLeft = new TQLabel( i18n( "Left:" ), gHead ); + headGrid->addWidget( lHeadLeft, 0, 0 ); + + eHeadLeft = new TQLineEdit( gHead ); + headGrid->addWidget( eHeadLeft, 1, 0 ); + eHeadLeft->setText( hf.headLeft ); + + TQLabel *lHeadMid = new TQLabel( i18n( "Mid:" ), gHead ); + headGrid->addWidget( lHeadMid, 0, 1 ); + + eHeadMid = new TQLineEdit( gHead ); + headGrid->addWidget( eHeadMid, 1, 1 ); + eHeadMid->setText( hf.headMid ); + + TQLabel *lHeadRight = new TQLabel( i18n( "Right:" ), gHead ); + headGrid->addWidget( lHeadRight, 0, 2 ); + + eHeadRight = new TQLineEdit( gHead ); + headGrid->addWidget( eHeadRight, 1, 2 ); + eHeadRight->setText( hf.headRight ); + + grid2->addMultiCellWidget( gHead, 0, 1, 0, 1 ); + + // ------------- footer --------------- + TQGroupBox *gFoot = new TQGroupBox( 0, Qt::Vertical, i18n( "Foot Line" ), tab2 ); + gFoot->layout()->setSpacing(KDialog::spacingHint()); + gFoot->layout()->setMargin(KDialog::marginHint()); + TQGridLayout *footGrid = new TQGridLayout( gFoot->layout(), 2, 3 ); + + TQLabel *lFootLeft = new TQLabel( i18n( "Left:" ), gFoot ); + footGrid->addWidget( lFootLeft, 0, 0 ); + + eFootLeft = new TQLineEdit( gFoot ); + footGrid->addWidget( eFootLeft, 1, 0 ); + eFootLeft->setText( hf.footLeft ); + + TQLabel *lFootMid = new TQLabel( i18n( "Mid:" ), gFoot ); + footGrid->addWidget( lFootMid, 0, 1 ); + + eFootMid = new TQLineEdit( gFoot ); + footGrid->addWidget( eFootMid, 1, 1 ); + eFootMid->setText( hf.footMid ); + + TQLabel *lFootRight = new TQLabel( i18n( "Right:" ), gFoot ); + footGrid->addWidget( lFootRight, 0, 2 ); + + eFootRight = new TQLineEdit( gFoot ); + footGrid->addWidget( eFootRight, 1, 2 ); + eFootRight->setText( hf.footRight ); + + grid2->addMultiCellWidget( gFoot, 2, 3, 0, 1 ); + + TQLabel *lMacros2 = new TQLabel( i18n( "You can insert several tags in the text:" ), tab2 ); + grid2->addMultiCellWidget( lMacros2, 4, 4, 0, 1 ); + + TQLabel *lMacros3 = new TQLabel( i18n("
  • <sheet> The sheet name
  • " + "
  • <page> The current page
  • " + "
  • <pages> The total number of pages
  • " + "
  • <name> The filename or URL
  • " + "
  • <file> The filename with complete path or the URL
"), tab2 ); + grid2->addMultiCellWidget( lMacros3, 5, 6, 0, 0, TQt::AlignTop ); + + TQLabel *lMacros4 = new TQLabel( i18n("
  • <time> The current time
  • " + "
  • <date> The current date
  • " + "
  • <author> Your full name
  • " + "
  • <org> Your organization
  • " + "
  • <email> Your email address
"), tab2 ); + grid2->addMultiCellWidget( lMacros4, 5, 6, 1, 1, TQt::AlignTop ); +} + +/*================================================================*/ +void KoPageLayoutDia::setupTab3() +{ + TQWidget *tab3 = addPage(i18n( "Col&umns" )); + TQHBoxLayout *lay = new TQHBoxLayout(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, TQT_SIGNAL( propertyChange(KoColumns&)), + this, TQT_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 ) +{ + TQWidget *tab4 = addPage(i18n( "H&eader && Footer" )); + TQHBoxLayout *lay = new TQHBoxLayout(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 diff --git a/kexi/3rdparty/kolibs/koUnit.cc b/kexi/3rdparty/kolibs/koUnit.cc deleted file mode 100644 index a2eb289a..00000000 --- a/kexi/3rdparty/kolibs/koUnit.cc +++ /dev/null @@ -1,219 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2001 David Faure - Copyright (C) 2004, Nicolas GOUTTE - - 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 -#include "KoUnit.h" -#ifndef SIMPLE_KOLIBS -# include -#endif - -#include -#include -#include - -#include -#include - -TQStringList KoUnit::listOfUnitName() -{ - TQStringList lst; - for ( uint i = 0 ; i <= KoUnit::U_LASTUNIT ; ++i ) - { - KoUnit::Unit unit = static_cast( i ); - lst.append( KoUnit::unitDescription( unit ) ); - } - return lst; -} - -TQString 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; - } -} - -TQString KoUnit::toUserStringValue( double ptValue, Unit unit ) -{ - return TDEGlobal::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 TQString& value, Unit unit, bool* ok ) -{ - return fromUserValue( TDEGlobal::locale()->readNumber( value, ok ), unit ); -} - -double KoUnit::parseValue( TQString value, double defaultVal ) -{ - value.simplifyWhiteSpace(); - value.remove( ' ' ); - - if( value.isEmpty() ) - return defaultVal; - - int index = value.find( TQRegExp( "[a-z]+$" ) ); - if ( index == -1 ) - return value.toDouble(); - - TQString 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 TQString &_unitName, bool* ok ) -{ - if ( ok ) - *ok = true; - if ( _unitName == TQString::fromLatin1( "mm" ) ) return U_MM; - if ( _unitName == TQString::fromLatin1( "cm" ) ) return U_CM; - if ( _unitName == TQString::fromLatin1( "dm" ) ) return U_DM; - if ( _unitName == TQString::fromLatin1( "in" ) - || _unitName == TQString::fromLatin1("inch") /*compat*/ ) return U_INCH; - if ( _unitName == TQString::fromLatin1( "pi" ) ) return U_PI; - if ( _unitName == TQString::fromLatin1( "dd" ) ) return U_DD; - if ( _unitName == TQString::fromLatin1( "cc" ) ) return U_CC; - if ( _unitName == TQString::fromLatin1( "pt" ) ) return U_PT; - if ( ok ) - *ok = false; - return U_PT; -} - -TQString KoUnit::unitName( Unit _unit ) -{ - if ( _unit == U_MM ) return TQString::fromLatin1( "mm" ); - if ( _unit == U_CM ) return TQString::fromLatin1( "cm" ); - if ( _unit == U_DM ) return TQString::fromLatin1( "dm" ); - if ( _unit == U_INCH ) return TQString::fromLatin1( "in" ); - if ( _unit == U_PI ) return TQString::fromLatin1( "pi" ); - if ( _unit == U_DD ) return TQString::fromLatin1( "dd" ); - if ( _unit == U_CC ) return TQString::fromLatin1( "cc" ); - return TQString::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.cpp b/kexi/3rdparty/kolibs/koUnit.cpp new file mode 100644 index 00000000..a2eb289a --- /dev/null +++ b/kexi/3rdparty/kolibs/koUnit.cpp @@ -0,0 +1,219 @@ +/* This file is part of the KDE project + Copyright (C) 2001 David Faure + Copyright (C) 2004, Nicolas GOUTTE + + 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 +#include "KoUnit.h" +#ifndef SIMPLE_KOLIBS +# include +#endif + +#include +#include +#include + +#include +#include + +TQStringList KoUnit::listOfUnitName() +{ + TQStringList lst; + for ( uint i = 0 ; i <= KoUnit::U_LASTUNIT ; ++i ) + { + KoUnit::Unit unit = static_cast( i ); + lst.append( KoUnit::unitDescription( unit ) ); + } + return lst; +} + +TQString 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; + } +} + +TQString KoUnit::toUserStringValue( double ptValue, Unit unit ) +{ + return TDEGlobal::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 TQString& value, Unit unit, bool* ok ) +{ + return fromUserValue( TDEGlobal::locale()->readNumber( value, ok ), unit ); +} + +double KoUnit::parseValue( TQString value, double defaultVal ) +{ + value.simplifyWhiteSpace(); + value.remove( ' ' ); + + if( value.isEmpty() ) + return defaultVal; + + int index = value.find( TQRegExp( "[a-z]+$" ) ); + if ( index == -1 ) + return value.toDouble(); + + TQString 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 TQString &_unitName, bool* ok ) +{ + if ( ok ) + *ok = true; + if ( _unitName == TQString::fromLatin1( "mm" ) ) return U_MM; + if ( _unitName == TQString::fromLatin1( "cm" ) ) return U_CM; + if ( _unitName == TQString::fromLatin1( "dm" ) ) return U_DM; + if ( _unitName == TQString::fromLatin1( "in" ) + || _unitName == TQString::fromLatin1("inch") /*compat*/ ) return U_INCH; + if ( _unitName == TQString::fromLatin1( "pi" ) ) return U_PI; + if ( _unitName == TQString::fromLatin1( "dd" ) ) return U_DD; + if ( _unitName == TQString::fromLatin1( "cc" ) ) return U_CC; + if ( _unitName == TQString::fromLatin1( "pt" ) ) return U_PT; + if ( ok ) + *ok = false; + return U_PT; +} + +TQString KoUnit::unitName( Unit _unit ) +{ + if ( _unit == U_MM ) return TQString::fromLatin1( "mm" ); + if ( _unit == U_CM ) return TQString::fromLatin1( "cm" ); + if ( _unit == U_DM ) return TQString::fromLatin1( "dm" ); + if ( _unit == U_INCH ) return TQString::fromLatin1( "in" ); + if ( _unit == U_PI ) return TQString::fromLatin1( "pi" ); + if ( _unit == U_DD ) return TQString::fromLatin1( "dd" ); + if ( _unit == U_CC ) return TQString::fromLatin1( "cc" ); + return TQString::fromLatin1( "pt" ); +} + +#ifndef SIMPLE_KOLIBS +void KoUnit::saveOasis(KoXmlWriter* settingsWriter, Unit _unit) +{ + settingsWriter->addConfigItem( "unit", unitName(_unit) ); +} +#endif diff --git a/kexi/3rdparty/kolibs/koUnitWidgets.cc b/kexi/3rdparty/kolibs/koUnitWidgets.cc deleted file mode 100644 index 097dfc25..00000000 --- a/kexi/3rdparty/kolibs/koUnitWidgets.cc +++ /dev/null @@ -1,454 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2002, Rob Buis(buis@kde.org) - Copyright (C) 2004, Nicolas GOUTTE - - 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 -#include -#include -#include -#include - - -// ---------------------------------------------------------------- -// Support classes - - -KoUnitDoubleValidator::KoUnitDoubleValidator( KoUnitDoubleBase *base, TQObject *parent, const char *name ) -: KDoubleValidator( parent, name ), m_base( base ) -{ -} - -TQValidator::State -KoUnitDoubleValidator::validate( TQString &s, int &pos ) const -{ - - kdDebug(30004) << "KoUnitDoubleValidator::validate : " << s << " at " << pos << endl; - TQValidator::State result = Acceptable; - - TQRegExp 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 TQString::stripWhiteSpace really necessary? - const TQString number ( s.left( res ).stripWhiteSpace() ); - const TQString 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; -} - - -TQString KoUnitDoubleBase::getVisibleText( double value ) const -{ - const TQString num ( TQString( "%1%2").arg( TDEGlobal::locale()->formatNumber( value, m_precision ), KoUnit::unitName( m_unit ) ) ); - kdDebug(30004) << "getVisibleText: " << TQString::number( value, 'f', 12 ) << " => " << num << endl; - return num; -} - -double KoUnitDoubleBase::toDouble( const TQString& str, bool* ok ) const -{ - TQString str2( str ); - /* TDELocale::readNumber wants the thousand separator exactly at 1000. - But when editing, it might be anywhere. So we need to remove it. */ - const TQString sep( TDEGlobal::locale()->thousandsSeparator() ); - if ( !sep.isEmpty() ) - str2.remove( sep ); - str2.remove( KoUnit::unitName( m_unit ) ); - const double dbl = TDEGlobal::locale()->readNumber( str2, ok ); - if ( ok ) - kdDebug(30004) << "toDouble:" << str << ": => :" << str2 << ": => " << TQString::number( dbl, 'f', 12 ) << endl; - else - kdWarning(30004) << "toDouble error:" << str << ": => :" << str2 << ":" << endl; - return dbl; -} - - -// ---------------------------------------------------------------- -// Widget classes - - -KoUnitDoubleSpinBox::KoUnitDoubleSpinBox( TQWidget *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 ); - TQSpinBox::setValidator( m_validator ); - setAcceptLocalizedNumbers( true ); - setUnit( KoUnit::U_PT ); - - connect(this, TQT_SIGNAL(valueChanged( double )), TQT_SLOT(privateValueChanged())); -} - - -KoUnitDoubleSpinBox::KoUnitDoubleSpinBox( TQWidget *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 ); - TQSpinBox::setValidator( m_validator ); - setAcceptLocalizedNumbers( true ); - setUnit( unit ); - changeValue( value ); - setLineStep( 0.5 ); - - connect(this, TQT_SIGNAL(valueChanged( double )), TQT_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( TQWidget *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( TQt::AlignRight ); - m_validator = new KoUnitDoubleValidator( this, this ); - setValidator( m_validator ); - setUnit( KoUnit::U_PT ); - changeValue( KoUnit::ptToUnit( 0.0, KoUnit::U_PT ) ); -} - -KoUnitDoubleLineEdit::KoUnitDoubleLineEdit( TQWidget *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( TQt::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( TQObject* o, TQEvent* ev ) -{ -#if 0 - if( ev->type() == TQEvent::FocusOut || ev->type() == TQEvent::Leave || ev->type() == TQEvent::Hide ) - { - bool ok; - double value = toDouble( text(), &ok ); - changeValue( value ); - return false; - } - else -#endif - return TQLineEdit::eventFilter( o, ev ); -} - -double KoUnitDoubleLineEdit::value( void ) const -{ - return KoUnit::fromUserValue( m_value, m_unit ); -} - - -// ---------------------------------------------------------------- - - -KoUnitDoubleComboBox::KoUnitDoubleComboBox( TQWidget *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( TQt::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, TQT_SIGNAL( activated( int ) ), this, TQT_SLOT( slotActivated( int ) ) ); -} - -KoUnitDoubleComboBox::KoUnitDoubleComboBox( TQWidget *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( TQt::AlignRight ); - m_validator = new KoUnitDoubleValidator( this, this ); - lineEdit()->setValidator( m_validator ); - setUnit( unit ); - changeValue( KoUnit::ptToUnit( value, unit ) ); - connect( this, TQT_SIGNAL( activated( int ) ), this, TQT_SLOT( slotActivated( int ) ) ); -} - -void -KoUnitDoubleComboBox::changeValue( double value ) -{ - TQString 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( TQObject* o, TQEvent* ev ) -{ -#if 0 - if( ev->type() == TQEvent::FocusOut || ev->type() == TQEvent::Leave || ev->type() == TQEvent::Hide ) - { - bool ok; - double value = toDouble( lineEdit()->text(), &ok ); - changeValue( value ); - return false; - } - else -#endif - return TQComboBox::eventFilter( o, ev ); -} - -double KoUnitDoubleComboBox::value( void ) const -{ - return KoUnit::fromUserValue( m_value, m_unit ); -} - - -// ---------------------------------------------------------------- - - -KoUnitDoubleSpinComboBox::KoUnitDoubleSpinComboBox( TQWidget *parent, const char *name ) - : TQWidget( parent ), m_step( 1.0 ) -{ - TQGridLayout *layout = new TQGridLayout( this, 2, 3 ); - //layout->setMargin( 2 ); - TQPushButton *up = new TQPushButton( "+", this ); - //up->setFlat( true ); - up->setMaximumHeight( 15 ); - up->setMaximumWidth( 15 ); - layout->addWidget( up, 0, 0 ); - connect( up, TQT_SIGNAL( clicked() ), this, TQT_SLOT( slotUpClicked() ) ); - - TQPushButton *down = new TQPushButton( "-", this ); - down->setMaximumHeight( 15 ); - down->setMaximumWidth( 15 ); - layout->addWidget( down, 1, 0 ); - connect( down, TQT_SIGNAL( clicked() ), this, TQT_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, TQT_SIGNAL( valueChanged( double ) ), this, TQT_SIGNAL( valueChanged( double ) ) ); - layout->addMultiCellWidget( m_combo, 0, 1, 2, 2 ); -} - -KoUnitDoubleSpinComboBox::KoUnitDoubleSpinComboBox( TQWidget *parent, double lower, double upper, double step, double value, - KoUnit::Unit unit, unsigned int precision, const char *name ) - : TQWidget( parent ), m_step( step )//, m_lowerInPoints( lower ), m_upperInPoints( upper ) -{ - TQGridLayout *layout = new TQGridLayout( this, 2, 3 ); - //layout->setMargin( 2 ); - TQPushButton *up = new TQPushButton( "+", this ); - //up->setFlat( true ); - up->setMaximumHeight( 15 ); - up->setMaximumWidth( 15 ); - layout->addWidget( up, 0, 0 ); - connect( up, TQT_SIGNAL( clicked() ), this, TQT_SLOT( slotUpClicked() ) ); - - TQPushButton *down = new TQPushButton( "-", this ); - down->setMaximumHeight( 15 ); - down->setMaximumWidth( 15 ); - layout->addWidget( down, 1, 0 ); - connect( down, TQT_SIGNAL( clicked() ), this, TQT_SLOT( slotDownClicked() ) ); - - m_combo = new KoUnitDoubleComboBox( this, KoUnit::ptToUnit( lower, unit ), KoUnit::ptToUnit( upper, unit ), value, unit, precision, name ); - connect( m_combo, TQT_SIGNAL( valueChanged( double ) ), this, TQT_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.cpp b/kexi/3rdparty/kolibs/koUnitWidgets.cpp new file mode 100644 index 00000000..097dfc25 --- /dev/null +++ b/kexi/3rdparty/kolibs/koUnitWidgets.cpp @@ -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 + + 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 +#include +#include +#include +#include + + +// ---------------------------------------------------------------- +// Support classes + + +KoUnitDoubleValidator::KoUnitDoubleValidator( KoUnitDoubleBase *base, TQObject *parent, const char *name ) +: KDoubleValidator( parent, name ), m_base( base ) +{ +} + +TQValidator::State +KoUnitDoubleValidator::validate( TQString &s, int &pos ) const +{ + + kdDebug(30004) << "KoUnitDoubleValidator::validate : " << s << " at " << pos << endl; + TQValidator::State result = Acceptable; + + TQRegExp 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 TQString::stripWhiteSpace really necessary? + const TQString number ( s.left( res ).stripWhiteSpace() ); + const TQString 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; +} + + +TQString KoUnitDoubleBase::getVisibleText( double value ) const +{ + const TQString num ( TQString( "%1%2").arg( TDEGlobal::locale()->formatNumber( value, m_precision ), KoUnit::unitName( m_unit ) ) ); + kdDebug(30004) << "getVisibleText: " << TQString::number( value, 'f', 12 ) << " => " << num << endl; + return num; +} + +double KoUnitDoubleBase::toDouble( const TQString& str, bool* ok ) const +{ + TQString str2( str ); + /* TDELocale::readNumber wants the thousand separator exactly at 1000. + But when editing, it might be anywhere. So we need to remove it. */ + const TQString sep( TDEGlobal::locale()->thousandsSeparator() ); + if ( !sep.isEmpty() ) + str2.remove( sep ); + str2.remove( KoUnit::unitName( m_unit ) ); + const double dbl = TDEGlobal::locale()->readNumber( str2, ok ); + if ( ok ) + kdDebug(30004) << "toDouble:" << str << ": => :" << str2 << ": => " << TQString::number( dbl, 'f', 12 ) << endl; + else + kdWarning(30004) << "toDouble error:" << str << ": => :" << str2 << ":" << endl; + return dbl; +} + + +// ---------------------------------------------------------------- +// Widget classes + + +KoUnitDoubleSpinBox::KoUnitDoubleSpinBox( TQWidget *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 ); + TQSpinBox::setValidator( m_validator ); + setAcceptLocalizedNumbers( true ); + setUnit( KoUnit::U_PT ); + + connect(this, TQT_SIGNAL(valueChanged( double )), TQT_SLOT(privateValueChanged())); +} + + +KoUnitDoubleSpinBox::KoUnitDoubleSpinBox( TQWidget *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 ); + TQSpinBox::setValidator( m_validator ); + setAcceptLocalizedNumbers( true ); + setUnit( unit ); + changeValue( value ); + setLineStep( 0.5 ); + + connect(this, TQT_SIGNAL(valueChanged( double )), TQT_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( TQWidget *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( TQt::AlignRight ); + m_validator = new KoUnitDoubleValidator( this, this ); + setValidator( m_validator ); + setUnit( KoUnit::U_PT ); + changeValue( KoUnit::ptToUnit( 0.0, KoUnit::U_PT ) ); +} + +KoUnitDoubleLineEdit::KoUnitDoubleLineEdit( TQWidget *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( TQt::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( TQObject* o, TQEvent* ev ) +{ +#if 0 + if( ev->type() == TQEvent::FocusOut || ev->type() == TQEvent::Leave || ev->type() == TQEvent::Hide ) + { + bool ok; + double value = toDouble( text(), &ok ); + changeValue( value ); + return false; + } + else +#endif + return TQLineEdit::eventFilter( o, ev ); +} + +double KoUnitDoubleLineEdit::value( void ) const +{ + return KoUnit::fromUserValue( m_value, m_unit ); +} + + +// ---------------------------------------------------------------- + + +KoUnitDoubleComboBox::KoUnitDoubleComboBox( TQWidget *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( TQt::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, TQT_SIGNAL( activated( int ) ), this, TQT_SLOT( slotActivated( int ) ) ); +} + +KoUnitDoubleComboBox::KoUnitDoubleComboBox( TQWidget *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( TQt::AlignRight ); + m_validator = new KoUnitDoubleValidator( this, this ); + lineEdit()->setValidator( m_validator ); + setUnit( unit ); + changeValue( KoUnit::ptToUnit( value, unit ) ); + connect( this, TQT_SIGNAL( activated( int ) ), this, TQT_SLOT( slotActivated( int ) ) ); +} + +void +KoUnitDoubleComboBox::changeValue( double value ) +{ + TQString 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( TQObject* o, TQEvent* ev ) +{ +#if 0 + if( ev->type() == TQEvent::FocusOut || ev->type() == TQEvent::Leave || ev->type() == TQEvent::Hide ) + { + bool ok; + double value = toDouble( lineEdit()->text(), &ok ); + changeValue( value ); + return false; + } + else +#endif + return TQComboBox::eventFilter( o, ev ); +} + +double KoUnitDoubleComboBox::value( void ) const +{ + return KoUnit::fromUserValue( m_value, m_unit ); +} + + +// ---------------------------------------------------------------- + + +KoUnitDoubleSpinComboBox::KoUnitDoubleSpinComboBox( TQWidget *parent, const char *name ) + : TQWidget( parent ), m_step( 1.0 ) +{ + TQGridLayout *layout = new TQGridLayout( this, 2, 3 ); + //layout->setMargin( 2 ); + TQPushButton *up = new TQPushButton( "+", this ); + //up->setFlat( true ); + up->setMaximumHeight( 15 ); + up->setMaximumWidth( 15 ); + layout->addWidget( up, 0, 0 ); + connect( up, TQT_SIGNAL( clicked() ), this, TQT_SLOT( slotUpClicked() ) ); + + TQPushButton *down = new TQPushButton( "-", this ); + down->setMaximumHeight( 15 ); + down->setMaximumWidth( 15 ); + layout->addWidget( down, 1, 0 ); + connect( down, TQT_SIGNAL( clicked() ), this, TQT_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, TQT_SIGNAL( valueChanged( double ) ), this, TQT_SIGNAL( valueChanged( double ) ) ); + layout->addMultiCellWidget( m_combo, 0, 1, 2, 2 ); +} + +KoUnitDoubleSpinComboBox::KoUnitDoubleSpinComboBox( TQWidget *parent, double lower, double upper, double step, double value, + KoUnit::Unit unit, unsigned int precision, const char *name ) + : TQWidget( parent ), m_step( step )//, m_lowerInPoints( lower ), m_upperInPoints( upper ) +{ + TQGridLayout *layout = new TQGridLayout( this, 2, 3 ); + //layout->setMargin( 2 ); + TQPushButton *up = new TQPushButton( "+", this ); + //up->setFlat( true ); + up->setMaximumHeight( 15 ); + up->setMaximumWidth( 15 ); + layout->addWidget( up, 0, 0 ); + connect( up, TQT_SIGNAL( clicked() ), this, TQT_SLOT( slotUpClicked() ) ); + + TQPushButton *down = new TQPushButton( "-", this ); + down->setMaximumHeight( 15 ); + down->setMaximumWidth( 15 ); + layout->addWidget( down, 1, 0 ); + connect( down, TQT_SIGNAL( clicked() ), this, TQT_SLOT( slotDownClicked() ) ); + + m_combo = new KoUnitDoubleComboBox( this, KoUnit::ptToUnit( lower, unit ), KoUnit::ptToUnit( upper, unit ), value, unit, precision, name ); + connect( m_combo, TQT_SIGNAL( valueChanged( double ) ), this, TQT_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(); +} + -- cgit v1.2.1