tdf#67905 adds an option to disable print preview in print dialog

Change-Id: Id6dd1724a1b8f61d94f0685f63d28b3cff19988f
This commit is contained in:
Daniel 2018-05-15 22:58:38 -03:00 committed by Daniel Silva
parent e3ce6ea30e
commit 2c23a96f7b
4 changed files with 73 additions and 13 deletions

View file

@ -181,13 +181,15 @@ namespace vcl
VclPtr<FixedText> mpNumPagesText;
VclPtr<PushButton> mpBackwardBtn;
VclPtr<PushButton> mpForwardBtn;
VclPtr<CheckBox> mpPreviewBox;
VclPtr<OKButton> mpOKButton;
VclPtr<CancelButton> mpCancelButton;
VclPtr<HelpButton> mpHelpButton;
OUString maPageStr;
OUString const maNoPageStr;
OUString maNoPageStr;
OUString maNoPreviewStr;
sal_Int32 mnCurPage;
sal_Int32 mnCachedPages;
@ -247,6 +249,7 @@ namespace vcl
bool isPrintToFile();
bool isCollate();
bool isSingleJobs();
bool hasPreview();
void previewForward();
void previewBackward();

View file

@ -113,6 +113,7 @@
#define SV_ACCESSERROR_NO_FONTS NC_("SV_ACCESSERROR_NO_FONTS", "No fonts could be found on the system.")
#define SV_PRINT_NOPAGES NC_("SV_PRINT_NOPAGES", "No pages")
#define SV_PRINT_NOPREVIEW NC_("SV_PRINT_NOPREVIEW", "Preview is disabled")
#define SV_PRINT_TOFILE_TXT NC_("SV_PRINT_TOFILE_TXT", "Print to File...")
#define SV_PRINT_DEFPRT_TXT NC_("SV_PRINT_DEFPRT_TXT", "Default printer")
#define SV_PRINT_PRINTPREVIEW_TXT NC_("SV_PRINT_PRINTPREVIEW_TXT", "Print preview")

View file

@ -653,6 +653,7 @@ PrintDialog::PrintDialog( vcl::Window* i_pParent, const std::shared_ptr<PrinterC
, maJobPage(m_pUIBuilder.get())
, maOptionsPage(m_pUIBuilder.get())
, maNoPageStr( VclResId( SV_PRINT_NOPAGES ) )
, maNoPreviewStr( VclResId( SV_PRINT_NOPREVIEW ) )
, mnCurPage( 0 )
, mnCachedPages( 0 )
, maPrintToFileText( VclResId( SV_PRINT_TOFILE_TXT ) )
@ -668,6 +669,7 @@ PrintDialog::PrintDialog( vcl::Window* i_pParent, const std::shared_ptr<PrinterC
get(mpPageEdit, "pageedit-nospin");
get(mpTabCtrl, "tabcontrol");
get(mpPreviewWindow, "preview");
get(mpPreviewBox, "previewbox");
// save printbutton text, gets exchanged occasionally with print to file
maPrintText = mpOKButton->GetText();
@ -717,9 +719,6 @@ PrintDialog::PrintDialog( vcl::Window* i_pParent, const std::shared_ptr<PrinterC
// not printing to file
maPController->resetPrinterOptions( false );
// get the first page
preparePreview( true, true );
// update the text fields for the printer
updatePrinterText();
@ -750,6 +749,7 @@ PrintDialog::PrintDialog( vcl::Window* i_pParent, const std::shared_ptr<PrinterC
mpHelpButton->SetClickHdl( LINK( this, PrintDialog, ClickHdl ) );
mpForwardBtn->SetClickHdl( LINK( this, PrintDialog, ClickHdl ) );
mpBackwardBtn->SetClickHdl( LINK( this, PrintDialog, ClickHdl ) );
mpPreviewBox->SetClickHdl( LINK( this, PrintDialog, ClickHdl ) );
maJobPage.mpCollateBox->SetToggleHdl( LINK( this, PrintDialog, ToggleHdl ) );
maJobPage.mpSetupButton->SetClickHdl( LINK( this, PrintDialog, ClickHdl ) );
@ -808,6 +808,7 @@ void PrintDialog::dispose()
mpNumPagesText.clear();
mpBackwardBtn.clear();
mpForwardBtn.clear();
mpPreviewBox.clear();
mpOKButton.clear();
mpCancelButton.clear();
mpHelpButton.clear();
@ -837,6 +838,16 @@ void PrintDialog::readFromSettings()
}
}
aValue = pItem->getValue( "PrintDialog", "HasPreview" );
if ( aValue.equalsIgnoreAsciiCase("true") )
{
mpPreviewBox->Check();
}
else
{
mpPreviewBox->Check( false );
}
// persistent window state
OUString aWinState( pItem->getValue( "PrintDialog",
"WindowState" ) );
@ -867,6 +878,9 @@ void PrintDialog::storeToSettings()
"WindowState",
OStringToOUString( GetWindowState(), RTL_TEXTENCODING_UTF8 )
);
pItem->setValue( "PrintDialog",
"HasPreview",
hasPreview() ? OUString("true") : OUString("false") );
pItem->Commit();
}
@ -885,7 +899,12 @@ bool PrintDialog::isSingleJobs()
return maOptionsPage.mpCollateSingleJobsBox->IsChecked();
}
static void setHelpId( vcl::Window* i_pWindow, const Sequence< OUString >& i_rHelpIds, sal_Int32 i_nIndex )
bool PrintDialog::hasPreview()
{
return mpPreviewBox->IsChecked();
}
void setHelpId( vcl::Window* i_pWindow, const Sequence< OUString >& i_rHelpIds, sal_Int32 i_nIndex )
{
if( i_nIndex >= 0 && i_nIndex < i_rHelpIds.getLength() )
i_pWindow->SetHelpId( OUStringToOString( i_rHelpIds.getConstArray()[i_nIndex], RTL_TEXTENCODING_UTF8 ) );
@ -1370,25 +1389,43 @@ void PrintDialog::setPreviewText()
void PrintDialog::preparePreview( bool i_bNewPage, bool i_bMayUseCache )
{
VclPtr<Printer> aPrt( maPController->getPrinter() );
Size aCurPageSize = aPrt->PixelToLogic( aPrt->GetPaperSizePixel(), MapMode( MapUnit::Map100thMM ) );
GDIMetaFile aMtf;
// page range may have changed depending on options
sal_Int32 nPages = maPController->getFilteredPageCount();
mnCachedPages = nPages;
mpPageEdit->SetMin( 1 );
mpPageEdit->SetMax( nPages );
setPreviewText();
if ( !hasPreview() )
{
mpPreviewWindow->setPreview( aMtf, aCurPageSize,
aPrt->GetPaperName(),
maNoPreviewStr,
aPrt->GetDPIX(), aPrt->GetDPIY(),
aPrt->GetPrinterOptions().IsConvertToGreyscales()
);
mpForwardBtn->Enable( false );
mpBackwardBtn->Enable( false );
mpPageEdit->Enable( false );
return;
}
if( mnCurPage >= nPages )
mnCurPage = nPages-1;
if( mnCurPage < 0 )
mnCurPage = 0;
setPreviewText();
mpPageEdit->SetMin( 1 );
mpPageEdit->SetMax( nPages );
if( i_bNewPage )
{
const MapMode aMapMode( MapUnit::Map100thMM );
GDIMetaFile aMtf;
VclPtr<Printer> aPrt( maPController->getPrinter() );
if( nPages > 0 )
{
PrinterController::PageSize aPageSize =
@ -1400,7 +1437,6 @@ void PrintDialog::preparePreview( bool i_bNewPage, bool i_bMayUseCache )
}
}
Size aCurPageSize = aPrt->PixelToLogic( aPrt->GetPaperSizePixel(), MapMode( MapUnit::Map100thMM ) );
mpPreviewWindow->setPreview( aMtf, aCurPageSize,
aPrt->GetPaperName(),
nPages > 0 ? OUString() : maNoPageStr,
@ -1650,6 +1686,10 @@ IMPL_LINK( PrintDialog, ClickHdl, Button*, pButton, void )
pHelp->Start( "vcl/ui/printdialog", mpOKButton );
}
}
else if ( pButton == mpPreviewBox )
{
preparePreview( true, true );
}
else if( pButton == mpForwardBtn )
{
previewForward();

View file

@ -273,6 +273,22 @@
<property name="fill">True</property>
<property name="position">1</property>
</packing>
<child>
<object class="GtkCheckButton" id="previewbox">
<property name="label" translatable="yes" context="printdialog|previewbox">Preview</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="xalign">0</property>
<property name="halign">center</property>
<property name="margin_left">30</property>
<property name="margin_right">30</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack_type">end</property>
</packing>
</child>
</child>
</object>
<packing>