2
//C- -------------------------------------------------------------------
4
//C- Copyright (c) 2002 Leon Bottou and Yann Le Cun.
5
//C- Copyright (c) 2001 AT&T
7
//C- This software is subject to, and may be distributed under, the
8
//C- GNU General Public License, Version 2. The license should have
9
//C- accompanied the software or you may obtain a copy of the license
10
//C- from the Free Software Foundation at http://www.fsf.org .
12
//C- This program is distributed in the hope that it will be useful,
13
//C- but WITHOUT ANY WARRANTY; without even the implied warranty of
14
//C- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
//C- GNU General Public License for more details.
17
//C- DjVuLibre-3.5 is derived from the DjVu(r) Reference Library
18
//C- distributed by Lizardtech Software. On July 19th 2002, Lizardtech
19
//C- Software authorized us to replace the original DjVu(r) Reference
20
//C- Library notice by the following text (see doc/lizard2002.djvu):
22
//C- ------------------------------------------------------------------
23
//C- | DjVu (r) Reference Library (v. 3.5)
24
//C- | Copyright (c) 1999-2001 LizardTech, Inc. All Rights Reserved.
25
//C- | The DjVu Reference Library is protected by U.S. Pat. No.
26
//C- | 6,058,214 and patents pending.
28
//C- | This software is subject to, and may be distributed under, the
29
//C- | GNU General Public License, Version 2. The license should have
30
//C- | accompanied the software or you may obtain a copy of the license
31
//C- | from the Free Software Foundation at http://www.fsf.org .
33
//C- | The computer code originally released by LizardTech under this
34
//C- | license and unmodified by other parties is deemed "the LIZARDTECH
35
//C- | ORIGINAL CODE." Subject to any third party intellectual property
36
//C- | claims, LizardTech grants recipient a worldwide, royalty-free,
37
//C- | non-exclusive license to make, use, sell, or otherwise dispose of
38
//C- | the LIZARDTECH ORIGINAL CODE or of programs derived from the
39
//C- | LIZARDTECH ORIGINAL CODE in compliance with the terms of the GNU
40
//C- | General Public License. This grant only confers the right to
41
//C- | infringe patent claims underlying the LIZARDTECH ORIGINAL CODE to
42
//C- | the extent such infringement is reasonably necessary to enable
43
//C- | recipient to make, have made, practice, sell, or otherwise dispose
44
//C- | of the LIZARDTECH ORIGINAL CODE (or portions thereof) and not to
45
//C- | any greater extent that may be necessary to utilize further
46
//C- | modifications or combinations.
48
//C- | The LIZARDTECH ORIGINAL CODE is provided "AS IS" WITHOUT WARRANTY
49
//C- | OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
50
//C- | TO ANY WARRANTY OF NON-INFRINGEMENT, OR ANY IMPLIED WARRANTY OF
51
//C- | MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
52
//C- +------------------------------------------------------------------
54
// $Id: qd_tbar_mode_piece.cpp,v 1.9 2003/11/07 22:08:18 leonb Exp $
55
// $Name: release_3_5_14 $
61
# pragma implementation
64
#include "qd_tbar_mode_piece.h"
68
#include "qd_toolbutt.h"
69
#include "djvu_base_res.h"
72
#include <qcombobox.h>
75
#include <qvalidator.h>
76
#include <qcheckbox.h>
82
// #define ONE2ONE_STR "1 : 1"
83
// #define STRETCH_STR "Stretch"
84
// #define FIT_WIDTH_STR "Fit Width"
85
// #define FIT_PAGE_STR "Fit Page"
87
class QDZoomValidator : public QValidator
90
virtual void fixup(QString &);
92
virtual State validate(QString &, int &);
94
virtual State validate(QString &, int &) const;
97
QDZoomValidator(QComboBox * parent, const char * name=0) :
98
QValidator(parent, name) {}
102
QDZoomValidator::fixup(QString & str)
110
QComboBox * menu=(QComboBox *) parent();
111
menu->setEditText(str=menu->text(menu->currentItem()));
115
QDZoomValidator::validate(QString & input, int & pos)
120
if (!input.length()) return Valid;
123
strncpy(buffer, input, 127); buffer[127]=0;
124
char * ptr=buffer+strlen(buffer)-1;
125
while(isspace(*ptr) || *ptr=='%') *ptr--=0;
129
int zoom=str.toInt(&status);
130
if (!status) return Invalid;
132
if (zoom>IDC_ZOOM_MAX-IDC_ZOOM_MIN) return Invalid;
133
if (zoom<=0) return Invalid;
135
if (str.length()==1) return Valid;
138
if (zoom<5 || zoom>IDC_ZOOM_MAX-IDC_ZOOM_MIN) return Invalid;
142
//****************************************************************************
143
//***************************** QDTBarModePiece ******************************
144
//****************************************************************************
147
QDTBarModePiece::setEnabled(bool en)
149
zoom_menu->setEnabled(en);
150
mode_menu->setEnabled(en);
151
zoom_in_butt->setEnabled(en);
152
zoom_out_butt->setEnabled(en);
154
zoom_select_butt->setEnabled(en);
155
text_select_butt->setEnabled(en);
156
pane_butt->setEnabled(en);
159
pin_butt->setEnabled(en);
162
static const int menu_items_size=10;
163
static const struct MenuItems {
166
} menu_items[menu_items_size] = {
167
{"300 %",IDC_ZOOM_MIN+300},
168
{"150 %",IDC_ZOOM_MIN+150},
169
{"100 %",IDC_ZOOM_MIN+100},
170
{"75 %",IDC_ZOOM_MIN+75},
171
{"50 %",IDC_ZOOM_MIN+50},
172
{"25 %",IDC_ZOOM_MIN+25},
173
{QT_TRANSLATE_NOOP("QDTBarModePiece","Fit Width"),IDC_ZOOM_WIDTH},
174
{QT_TRANSLATE_NOOP("QDTBarModePiece","Fit Page"),IDC_ZOOM_PAGE},
175
{"1 : 1",IDC_ZOOM_ONE2ONE},
176
{QT_TRANSLATE_NOOP("QDTBarModePiece","Stretch"),IDC_ZOOM_STRETCH},
179
QDTBarModePiece::QDTBarModePiece(QWidget * toolbar)
180
: QDTBarPiece(toolbar)
182
if ( dynamic_cast<QDToolBar *>(toolbar) )
183
qdtoolbar_child=TRUE;
185
qdtoolbar_child=FALSE;
187
mode_menu=new QComboBox(FALSE, toolbar, "mode_menu");
188
mode_menu->insertItem(tr("Color"));
189
mode_menu->insertItem(tr("B&W"));
190
mode_menu->insertItem(tr("Fore"));
191
mode_menu->insertItem(tr("Back"));
192
connect(mode_menu, SIGNAL(activated(int)), this, SLOT(slotMode(int)));
193
QToolTip::add(mode_menu, tr("Display mode"));
195
if ( qdtoolbar_child )
196
((QDToolBar *)toolbar)->addLeftWidget(mode_menu);
198
zoom_menu=new QComboBox(TRUE, toolbar, "zoom_menu");
199
zoom_menu->setInsertionPolicy(QComboBox::NoInsertion);
200
zoom_menu->setValidator(new QDZoomValidator(zoom_menu));
202
for(i=0;i<menu_items_size;i++)
204
zoom_menu->insertItem(tr(menu_items[i].str));
206
connect(zoom_menu, SIGNAL(activated(const QString &)),
207
this, SLOT(slotZoom(const QString &)));
208
QToolTip::add(zoom_menu, tr("Zoom"));
209
if ( qdtoolbar_child )
210
((QDToolBar *)toolbar)->addLeftWidget(zoom_menu);
212
zoom_in_butt=new QDToolButton(*CINData::get("ppm_vzoom_in"), true,
213
IDC_ZOOM_ZOOMIN, toolbar, tr("Zoom In"));
214
connect(zoom_in_butt, SIGNAL(clicked(void)), this, SLOT(slotZoom(void)));
216
zoom_out_butt=new QDToolButton(*CINData::get("ppm_vzoom_out"), true,
217
IDC_ZOOM_ZOOMOUT, toolbar, tr("Zoom Out"));
218
connect(zoom_out_butt, SIGNAL(clicked(void)), this, SLOT(slotZoom(void)));
220
if ( qdtoolbar_child )
221
((QDToolBar *)toolbar)->addLeftWidgets(zoom_in_butt, zoom_out_butt);
223
pane_butt=new QDToolButton(*CINData::get("ppm_hand1"), true,
224
IDC_PANE, toolbar, tr("Pane Mode"));
225
pane_butt->setToggleButton(TRUE);
226
connect(pane_butt, SIGNAL(clicked(void)),
227
this, SLOT(slotPaneMode(void)));
229
zoom_select_butt=new QDToolButton(*CINData::get("ppm_zoomselect"), true,
230
IDC_ZOOM_SELECT, toolbar,
231
tr("Zoom Selected Area"));
232
zoom_select_butt->setToggleButton(TRUE);
233
connect(zoom_select_butt, SIGNAL(clicked(void)),
234
this, SLOT(slotPaneMode(void)));
236
text_select_butt=new QDToolButton(*CINData::get("ppm_textselect"), true,
237
IDC_TEXT_SELECT, toolbar,
238
tr("Select Text in Selected Area"));
239
text_select_butt->setToggleButton(TRUE);
240
connect(text_select_butt, SIGNAL(clicked(void)),
241
this, SLOT(slotPaneMode(void)));
243
if ( qdtoolbar_child )
244
((QDToolBar *)toolbar)->addLeftWidgets(pane_butt,
248
if ( qdtoolbar_child )
250
pin_butt=new QDToolButton(*CINData::get("ppm_vpin_out"), false,
251
-1, toolbar, tr("Stick"));
252
pin_butt->setToggleButton(TRUE);
253
pin_butt->setOnPixmap(*CINData::get("ppm_vpin_in"));
254
connect(pin_butt, SIGNAL(toggled(bool)), this, SIGNAL(sigStick(bool)));
255
((QDToolBar *)toolbar)->addRightWidget(pin_butt);
257
((QDToolBar *)toolbar)->addPiece(this);
267
QDTBarModePiece::setOptions(int opts)
270
b = !(opts & QDBase::OverrideFlags::TOOLBAR_NO_RESCOMBO);
271
showOrHide(zoom_menu, b);
272
b = !(opts & QDBase::OverrideFlags::TOOLBAR_NO_DISPCOMBO);
273
showOrHide(mode_menu, b);
274
b = !(opts & QDBase::OverrideFlags::TOOLBAR_NO_ZOOM);
275
showOrHide(zoom_in_butt, b);
276
showOrHide(zoom_out_butt, b);
277
b = !(opts & QDBase::OverrideFlags::TOOLBAR_NO_PAN);
278
showOrHide(pane_butt, b);
279
b = !(opts & QDBase::OverrideFlags::TOOLBAR_NO_ZOOMSEL);
280
showOrHide(zoom_select_butt, b);
281
b = !(opts & QDBase::OverrideFlags::TOOLBAR_NO_TEXTSEL);
282
showOrHide(text_select_butt, b);
287
QDTBarModePiece::update(int cmd_mode, bool mode_enabled, int cmd_zoom, int zoom,
288
int pane_mode, int has_text)
291
for(i=0;i<menu_items_size;i++)
293
if(cmd_zoom == menu_items[i].zoom)
295
zoom_menu->setCurrentItem(i);
299
if(i==menu_items_size)
302
sprintf(buffer, "%d %%", zoom);
303
zoom_menu->setEditText(buffer);
306
zoom_in_butt->setEnabled(zoom<IDC_ZOOM_MAX-IDC_ZOOM_MIN);
307
zoom_out_butt->setEnabled(zoom>5);
309
pane_butt->setOn(pane_mode==IDC_PANE);
310
zoom_select_butt->setOn(pane_mode==IDC_ZOOM_SELECT);
313
if (!text_select_butt->isEnabled())
314
text_select_butt->setEnabled(true);
315
text_select_butt->setOn(pane_mode==IDC_TEXT_SELECT);
319
if (text_select_butt->isEnabled())
320
text_select_butt->setEnabled(false);
326
case IDC_DISPLAY_COLOR:
327
mode_menu->setCurrentItem(0);
329
case IDC_DISPLAY_BLACKWHITE:
330
mode_menu->setCurrentItem(1);
332
case IDC_DISPLAY_FOREGROUND:
333
mode_menu->setCurrentItem(2);
335
case IDC_DISPLAY_BACKGROUND:
336
mode_menu->setCurrentItem(3);
342
if ( !qdtoolbar_child )
343
zoom_menu->setEnabled(true);
345
mode_menu->setEnabled(mode_enabled);
347
zoom_menu->setFixedSize(zoom_menu->sizeHint());
348
mode_menu->setFixedSize(mode_menu->sizeHint());
350
// Keep everything disabled if the toolbar is disabled.
351
if (!toolbar->isEnabled()) setEnabled(false);
355
QDTBarModePiece::isStuck(void) const
357
if ( !pin_butt ) return FALSE;
358
return pin_butt->isOn();
362
QDTBarModePiece::stick(bool en)
369
QDTBarModePiece::slotZoom(const QString & qstr)
372
for(i=0;i<menu_items_size;i++)
374
if(qstr==tr(menu_items[i].str))
376
emit sigSetZoom(menu_items[i].zoom);
380
if(i == menu_items_size)
382
const char * const str=qstr;
386
emit sigSetZoom(i+IDC_ZOOM_MIN);
392
QDTBarModePiece::slotZoom(void)
394
const QObject * obj=sender();
395
if (obj && obj->isWidgetType() && obj->inherits("QDToolButton"))
397
const QDToolButton * butt=(QDToolButton *) obj;
398
emit sigSetZoom(butt->cmd);
403
QDTBarModePiece::slotPaneMode(void)
405
const QObject * obj=sender();
406
if (obj && obj->inherits("QDToolButton") && ((QDToolButton *)obj)->isToggleButton())
408
QDToolButton * butt=(QDToolButton *) obj;
412
// a bit inefficient, but I don't want to use button group either
413
zoom_select_butt->setOn(FALSE);
414
text_select_butt->setOn(FALSE);
415
pane_butt->setOn(FALSE);
418
emit sigSetPaneMode(butt->cmd);
423
QDTBarModePiece::slotMode(int index)
428
emit sigSetMode(IDC_DISPLAY_COLOR);
431
emit sigSetMode(IDC_DISPLAY_BLACKWHITE);
434
emit sigSetMode(IDC_DISPLAY_FOREGROUND);
437
emit sigSetMode(IDC_DISPLAY_BACKGROUND);