You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
403 lines
14 KiB
403 lines
14 KiB
15 years ago
|
/* 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>
|
||
|
|
||
12 years ago
|
#include <tdelocale.h>
|
||
15 years ago
|
#include <kiconloader.h>
|
||
12 years ago
|
#include <tdemessagebox.h>
|
||
15 years ago
|
|
||
14 years ago
|
#include <tqlabel.h>
|
||
13 years ago
|
#include <tqlayout.h>
|
||
14 years ago
|
#include <tqpainter.h>
|
||
|
#include <tqlineedit.h>
|
||
|
#include <tqbuttongroup.h>
|
||
|
#include <tqradiobutton.h>
|
||
|
#include <tqcheckbox.h>
|
||
|
#include <tqhbox.h>
|
||
|
#include <tqvgroupbox.h>
|
||
|
#include <tqhbuttongroup.h>
|
||
15 years ago
|
|
||
|
/******************************************************************/
|
||
|
/* class KoPagePreview */
|
||
|
/******************************************************************/
|
||
|
|
||
|
/*===================== constrcutor ==============================*/
|
||
13 years ago
|
KoPagePreview::KoPagePreview( TQWidget* parent, const char *name, const KoPageLayout& layout )
|
||
13 years ago
|
: TQGroupBox( i18n( "Page Preview" ), parent, name )
|
||
15 years ago
|
{
|
||
13 years ago
|
setPageLayout( layout );
|
||
15 years ago
|
columns = 1;
|
||
|
setMinimumSize( 150, 150 );
|
||
|
}
|
||
|
|
||
|
/*====================== destructor ==============================*/
|
||
|
KoPagePreview::~KoPagePreview()
|
||
|
{
|
||
|
}
|
||
|
|
||
13 years ago
|
/*=================== set layout =================================*/
|
||
|
void KoPagePreview::setPageLayout( const KoPageLayout &layout )
|
||
15 years ago
|
{
|
||
|
// 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()) );
|
||
|
|
||
13 years ago
|
m_pageWidth = layout.ptWidth * resolutionX;
|
||
|
m_pageHeight = layout.ptHeight * resolutionY;
|
||
15 years ago
|
|
||
|
double zh = 110.0 / m_pageHeight;
|
||
|
double zw = 110.0 / m_pageWidth;
|
||
14 years ago
|
double z = TQMIN( zw, zh );
|
||
15 years ago
|
|
||
|
m_pageWidth *= z;
|
||
|
m_pageHeight *= z;
|
||
|
|
||
13 years ago
|
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;
|
||
15 years ago
|
|
||
13 years ago
|
repaint( true );
|
||
15 years ago
|
}
|
||
|
|
||
13 years ago
|
/*=================== set layout =================================*/
|
||
15 years ago
|
void KoPagePreview::setPageColumns( const KoColumns &_columns )
|
||
|
{
|
||
|
columns = _columns.columns;
|
||
13 years ago
|
repaint( true );
|
||
15 years ago
|
}
|
||
|
|
||
|
/*======================== draw contents =========================*/
|
||
14 years ago
|
void KoPagePreview::drawContents( TQPainter *painter )
|
||
15 years ago
|
{
|
||
|
double cw = m_textFrameWidth;
|
||
|
if(columns!=1)
|
||
|
cw/=static_cast<double>(columns);
|
||
|
|
||
|
painter->setBrush( white );
|
||
14 years ago
|
painter->setPen( TQPen( black ) );
|
||
15 years ago
|
|
||
|
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 );
|
||
|
|
||
14 years ago
|
painter->setBrush( TQBrush( black, HorPattern ) );
|
||
15 years ago
|
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 ===============================*/
|
||
13 years ago
|
KoPageLayoutDia::KoPageLayoutDia( TQWidget* parent, const char* name,
|
||
13 years ago
|
const KoPageLayout& layout,
|
||
15 years ago
|
const KoHeadFoot& hf, int tabs,
|
||
|
KoUnit::Unit unit, bool modal )
|
||
|
: KDialogBase( KDialogBase::Tabbed, i18n("Page Layout"), KDialogBase::Ok | KDialogBase::Cancel,
|
||
13 years ago
|
KDialogBase::Ok, parent, name, modal)
|
||
15 years ago
|
{
|
||
|
|
||
|
flags = tabs;
|
||
13 years ago
|
m_layout = layout;
|
||
15 years ago
|
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 );
|
||
|
|
||
14 years ago
|
setFocusPolicy( TQ_StrongFocus );
|
||
15 years ago
|
setFocus();
|
||
|
}
|
||
|
|
||
|
/*==================== constructor ===============================*/
|
||
13 years ago
|
KoPageLayoutDia::KoPageLayoutDia( TQWidget* parent, const char* name,
|
||
13 years ago
|
const KoPageLayout& layout,
|
||
15 years ago
|
const KoHeadFoot& hf,
|
||
|
const KoColumns& columns,
|
||
|
const KoKWHeaderFooter& kwhf,
|
||
|
int tabs, KoUnit::Unit unit )
|
||
|
: KDialogBase( KDialogBase::Tabbed, i18n("Page Layout"), KDialogBase::Ok | KDialogBase::Cancel,
|
||
13 years ago
|
KDialogBase::Ok, parent, name, true)
|
||
15 years ago
|
{
|
||
|
flags = tabs;
|
||
|
|
||
13 years ago
|
m_layout = layout;
|
||
15 years ago
|
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);
|
||
|
|
||
14 years ago
|
setFocusPolicy( TQ_StrongFocus );
|
||
15 years ago
|
setFocus();
|
||
|
}
|
||
|
|
||
|
/*===================== destructor ===============================*/
|
||
|
KoPageLayoutDia::~KoPageLayoutDia()
|
||
|
{
|
||
|
}
|
||
|
|
||
|
/*======================= show dialog ============================*/
|
||
13 years ago
|
bool KoPageLayoutDia::pageLayout( KoPageLayout& layout, KoHeadFoot& hf, int tabs, KoUnit::Unit& unit, TQWidget* parent )
|
||
15 years ago
|
{
|
||
|
bool res = false;
|
||
13 years ago
|
KoPageLayoutDia *dlg = new KoPageLayoutDia( parent, "PageLayout", layout, hf, tabs, unit );
|
||
15 years ago
|
|
||
14 years ago
|
if ( dlg->exec() == TQDialog::Accepted ) {
|
||
15 years ago
|
res = true;
|
||
13 years ago
|
if ( tabs & FORMAT_AND_BORDERS ) layout = dlg->layout();
|
||
15 years ago
|
if ( tabs & HEADER_AND_FOOTER ) hf = dlg->headFoot();
|
||
|
unit = dlg->unit();
|
||
|
}
|
||
|
|
||
|
delete dlg;
|
||
|
|
||
|
return res;
|
||
|
}
|
||
|
|
||
|
/*======================= show dialog ============================*/
|
||
13 years ago
|
bool KoPageLayoutDia::pageLayout( KoPageLayout& layout, KoHeadFoot& hf, KoColumns& columns,
|
||
13 years ago
|
KoKWHeaderFooter &_kwhf, int tabs, KoUnit::Unit& unit, TQWidget* parent )
|
||
15 years ago
|
{
|
||
|
bool res = false;
|
||
13 years ago
|
KoPageLayoutDia *dlg = new KoPageLayoutDia( parent, "PageLayout", layout, hf, columns, _kwhf, tabs, unit );
|
||
15 years ago
|
|
||
14 years ago
|
if ( dlg->exec() == TQDialog::Accepted ) {
|
||
15 years ago
|
res = true;
|
||
13 years ago
|
if ( tabs & FORMAT_AND_BORDERS ) layout = dlg->layout();
|
||
15 years ago
|
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;
|
||
|
}
|
||
|
|
||
13 years ago
|
/*===================== get a standard page layout ===============*/
|
||
15 years ago
|
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 )
|
||
|
{
|
||
14 years ago
|
TQWidget *tab1 = addPage(i18n( "Page Size && &Margins" ));
|
||
|
TQHBoxLayout *lay = new TQHBoxLayout(tab1);
|
||
15 years ago
|
m_pageSizeTab = new KoPageLayoutSize(tab1, m_layout, m_unit, m_column, !(flags & DISABLE_UNIT), enableBorders );
|
||
|
lay->addWidget(m_pageSizeTab);
|
||
|
m_pageSizeTab->show();
|
||
14 years ago
|
connect (m_pageSizeTab, TQT_SIGNAL( propertyChange(KoPageLayout&)),
|
||
|
this, TQT_SLOT (sizeUpdated( KoPageLayout&)));
|
||
15 years ago
|
}
|
||
|
|
||
13 years ago
|
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;
|
||
15 years ago
|
if(m_columnsTab)
|
||
13 years ago
|
m_columnsTab->setLayout(layout);
|
||
15 years ago
|
}
|
||
|
|
||
|
/*================ setup header and footer tab ===================*/
|
||
|
void KoPageLayoutDia::setupTab2( const KoHeadFoot& hf )
|
||
|
{
|
||
14 years ago
|
TQWidget *tab2 = addPage(i18n( "H&eader && Footer" ));
|
||
|
TQGridLayout *grid2 = new TQGridLayout( tab2, 7, 2, 0, KDialog::spacingHint() );
|
||
15 years ago
|
|
||
|
// ------------- header ---------------
|
||
14 years ago
|
TQGroupBox *gHead = new TQGroupBox( 0, Qt::Vertical, i18n( "Head Line" ), tab2 );
|
||
13 years ago
|
gHead->layout()->setSpacing(KDialog::spacingHint());
|
||
|
gHead->layout()->setMargin(KDialog::marginHint());
|
||
|
TQGridLayout *headGrid = new TQGridLayout( gHead->layout(), 2, 3 );
|
||
15 years ago
|
|
||
14 years ago
|
TQLabel *lHeadLeft = new TQLabel( i18n( "Left:" ), gHead );
|
||
15 years ago
|
headGrid->addWidget( lHeadLeft, 0, 0 );
|
||
|
|
||
14 years ago
|
eHeadLeft = new TQLineEdit( gHead );
|
||
15 years ago
|
headGrid->addWidget( eHeadLeft, 1, 0 );
|
||
|
eHeadLeft->setText( hf.headLeft );
|
||
|
|
||
14 years ago
|
TQLabel *lHeadMid = new TQLabel( i18n( "Mid:" ), gHead );
|
||
15 years ago
|
headGrid->addWidget( lHeadMid, 0, 1 );
|
||
|
|
||
14 years ago
|
eHeadMid = new TQLineEdit( gHead );
|
||
15 years ago
|
headGrid->addWidget( eHeadMid, 1, 1 );
|
||
|
eHeadMid->setText( hf.headMid );
|
||
|
|
||
14 years ago
|
TQLabel *lHeadRight = new TQLabel( i18n( "Right:" ), gHead );
|
||
15 years ago
|
headGrid->addWidget( lHeadRight, 0, 2 );
|
||
|
|
||
14 years ago
|
eHeadRight = new TQLineEdit( gHead );
|
||
15 years ago
|
headGrid->addWidget( eHeadRight, 1, 2 );
|
||
|
eHeadRight->setText( hf.headRight );
|
||
|
|
||
|
grid2->addMultiCellWidget( gHead, 0, 1, 0, 1 );
|
||
|
|
||
|
// ------------- footer ---------------
|
||
14 years ago
|
TQGroupBox *gFoot = new TQGroupBox( 0, Qt::Vertical, i18n( "Foot Line" ), tab2 );
|
||
13 years ago
|
gFoot->layout()->setSpacing(KDialog::spacingHint());
|
||
|
gFoot->layout()->setMargin(KDialog::marginHint());
|
||
|
TQGridLayout *footGrid = new TQGridLayout( gFoot->layout(), 2, 3 );
|
||
15 years ago
|
|
||
14 years ago
|
TQLabel *lFootLeft = new TQLabel( i18n( "Left:" ), gFoot );
|
||
15 years ago
|
footGrid->addWidget( lFootLeft, 0, 0 );
|
||
|
|
||
14 years ago
|
eFootLeft = new TQLineEdit( gFoot );
|
||
15 years ago
|
footGrid->addWidget( eFootLeft, 1, 0 );
|
||
|
eFootLeft->setText( hf.footLeft );
|
||
|
|
||
14 years ago
|
TQLabel *lFootMid = new TQLabel( i18n( "Mid:" ), gFoot );
|
||
15 years ago
|
footGrid->addWidget( lFootMid, 0, 1 );
|
||
|
|
||
14 years ago
|
eFootMid = new TQLineEdit( gFoot );
|
||
15 years ago
|
footGrid->addWidget( eFootMid, 1, 1 );
|
||
|
eFootMid->setText( hf.footMid );
|
||
|
|
||
14 years ago
|
TQLabel *lFootRight = new TQLabel( i18n( "Right:" ), gFoot );
|
||
15 years ago
|
footGrid->addWidget( lFootRight, 0, 2 );
|
||
|
|
||
14 years ago
|
eFootRight = new TQLineEdit( gFoot );
|
||
15 years ago
|
footGrid->addWidget( eFootRight, 1, 2 );
|
||
|
eFootRight->setText( hf.footRight );
|
||
|
|
||
|
grid2->addMultiCellWidget( gFoot, 2, 3, 0, 1 );
|
||
|
|
||
14 years ago
|
TQLabel *lMacros2 = new TQLabel( i18n( "You can insert several tags in the text:" ), tab2 );
|
||
15 years ago
|
grid2->addMultiCellWidget( lMacros2, 4, 4, 0, 1 );
|
||
|
|
||
14 years ago
|
TQLabel *lMacros3 = new TQLabel( i18n("<qt><ul><li><sheet> The sheet name</li>"
|
||
15 years ago
|
"<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 );
|
||
14 years ago
|
grid2->addMultiCellWidget( lMacros3, 5, 6, 0, 0, TQt::AlignTop );
|
||
15 years ago
|
|
||
14 years ago
|
TQLabel *lMacros4 = new TQLabel( i18n("<qt><ul><li><time> The current time</li>"
|
||
15 years ago
|
"<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 );
|
||
14 years ago
|
grid2->addMultiCellWidget( lMacros4, 5, 6, 1, 1, TQt::AlignTop );
|
||
15 years ago
|
}
|
||
|
|
||
|
/*================================================================*/
|
||
|
void KoPageLayoutDia::setupTab3()
|
||
|
{
|
||
14 years ago
|
TQWidget *tab3 = addPage(i18n( "Col&umns" ));
|
||
|
TQHBoxLayout *lay = new TQHBoxLayout(tab3);
|
||
15 years ago
|
m_columnsTab = new KoPageLayoutColumns(tab3, m_column, m_unit, m_layout);
|
||
13 years ago
|
m_columnsTab->layout()->setMargin(0);
|
||
15 years ago
|
lay->addWidget(m_columnsTab);
|
||
|
m_columnsTab->show();
|
||
14 years ago
|
connect (m_columnsTab, TQT_SIGNAL( propertyChange(KoColumns&)),
|
||
|
this, TQT_SLOT (columnsUpdated( KoColumns&)));
|
||
15 years ago
|
}
|
||
|
|
||
|
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 )
|
||
|
{
|
||
14 years ago
|
TQWidget *tab4 = addPage(i18n( "H&eader && Footer" ));
|
||
|
TQHBoxLayout *lay = new TQHBoxLayout(tab4);
|
||
15 years ago
|
m_headerTab = new KoPageLayoutHeader(tab4, m_unit, kwhf);
|
||
13 years ago
|
m_headerTab->layout()->setMargin(0);
|
||
15 years ago
|
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>
|