• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdegraphics API Reference
  • KDE Home
  • Contact Us
 

libs/libksane/libksane

  • sources
  • kde-4.14
  • kdegraphics
  • libs
  • libksane
  • libksane
ksane_widget.cpp
Go to the documentation of this file.
1 /* ============================================================
2  *
3  * This file is part of the KDE project
4  *
5  * Date : 2009-01-24
6  * Description : Sane interface for KDE
7  *
8  * Copyright (C) 2007-2010 by Kare Sars <kare dot sars at iki dot fi>
9  * Copyright (C) 2009 by Matthias Nagl <matthias at nagl dot info>
10  * Copyright (C) 2009 by Grzegorz Kurtyka <grzegorz dot kurtyka at gmail dot com>
11  * Copyright (C) 2007-2008 by Gilles Caulier <caulier dot gilles at gmail dot com>
12  *
13  * This library is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU Lesser General Public
15  * License as published by the Free Software Foundation; either
16  * version 2.1 of the License, or (at your option) version 3, or any
17  * later version accepted by the membership of KDE e.V. (or its
18  * successor approved by the membership of KDE e.V.), which shall
19  * act as a proxy defined in Section 6 of version 3 of the license.
20  *
21  * This library is distributed in the hope that it will be useful,
22  * but WITHOUT ANY WARRANTY; without even the implied warranty of
23  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24  * Lesser General Public License for more details.
25  *
26  * You should have received a copy of the GNU Lesser General Public
27  * License along with this program. If not, see <http://www.gnu.org/licenses/>.
28  *
29  * ============================================================ */
30 
31 #include "ksane.h"
32 #include "ksane.moc"
33 
34 #include <unistd.h>
35 
36 // Qt includes
37 #include <QApplication>
38 #include <QVarLengthArray>
39 #include <QLabel>
40 #include <QSplitter>
41 #include <QMutex>
42 #include <QPointer>
43 
44 // KDE includes
45 #include <kpassworddialog.h>
46 #include <kwallet.h>
47 #include <kpushbutton.h>
48 
49 // Local includes
50 #include "ksane_widget_private.h"
51 #include "ksane_option.h"
52 #include "ksane_opt_button.h"
53 #include "ksane_opt_checkbox.h"
54 #include "ksane_opt_combo.h"
55 #include "ksane_opt_entry.h"
56 #include "ksane_opt_fslider.h"
57 #include "ksane_opt_gamma.h"
58 #include "ksane_opt_slider.h"
59 #include "ksane_device_dialog.h"
60 #include "labeled_gamma.h"
61 
62 namespace KSaneIface
63 {
64 static int s_objectCount = 0;
65 static QMutex s_objectMutex;
66 
67 static const QString InvetColorsOption = QString("KSane::InvertColors");
68 
69 KSaneWidget::KSaneWidget(QWidget* parent)
70  : QWidget(parent), d(new KSaneWidgetPrivate(this))
71 {
72  SANE_Int version;
73  SANE_Status status;
74 
75  //kDebug() << "The language is:" << KGlobal::locale()->language();
76  //kDebug() << "Languagelist" << KGlobal::locale()->languageList();
77  KGlobal::locale()->insertCatalog("libksane");
78  KGlobal::locale()->insertCatalog("sane-backends");
79 
80  s_objectMutex.lock();
81  s_objectCount++;
82 
83  if (s_objectCount == 1) {
84  // only call sane init for the first instance
85  status = sane_init(&version, &KSaneAuth::authorization);
86  if (status != SANE_STATUS_GOOD) {
87  kDebug() << "libksane: sane_init() failed("
88  << sane_strstatus(status) << ")";
89  }
90  else {
91  //kDebug() << "Sane Version = "
92  // << SANE_VERSION_MAJOR(version) << "."
93  // << SANE_VERSION_MINORparent(version) << "."
94  // << SANE_VERSION_BUILD(version);
95  }
96  }
97  s_objectMutex.unlock();
98 
99  // read the device list to get a list of vendor and model info
100  d->m_findDevThread->start();
101 
102  d->m_readValsTmr.setSingleShot(true);
103  connect(&d->m_readValsTmr, SIGNAL(timeout()), d, SLOT(valReload()));
104 
105  d->m_updProgressTmr.setSingleShot(false);
106  d->m_updProgressTmr.setInterval(300);
107  connect(&d->m_updProgressTmr, SIGNAL(timeout()), d, SLOT(updateProgress()));
108 
109  // Create the static UI
110  // create the preview
111  d->m_previewViewer = new KSaneViewer(&(d->m_previewImg), this);
112  connect(d->m_previewViewer, SIGNAL(newSelection(float,float,float,float)),
113  d, SLOT(handleSelection(float,float,float,float)));
114 
115 
116  d->m_warmingUp = new QLabel;
117  d->m_warmingUp->setText(i18n("Waiting for the scan to start."));
118  d->m_warmingUp->setAlignment(Qt::AlignCenter);
119  d->m_warmingUp->setAutoFillBackground(true);
120  d->m_warmingUp->setBackgroundRole(QPalette::Highlight);
121  //d->m_warmingUp->setForegroundRole(QPalette::HighlightedText);
122  d->m_warmingUp->hide();
123 
124  d->m_progressBar = new QProgressBar;
125  d->m_progressBar->setMaximum(100);
126 
127  d->m_cancelBtn = new KPushButton;
128  d->m_cancelBtn->setIcon(KIcon("process-stop"));
129  d->m_cancelBtn->setToolTip(i18n("Cancel current scan operation"));
130  connect(d->m_cancelBtn, SIGNAL(clicked()), this, SLOT(scanCancel()));
131 
132  d->m_activityFrame = new QWidget;
133  QHBoxLayout *progress_lay = new QHBoxLayout(d->m_activityFrame);
134  progress_lay->setContentsMargins(0,0,0,0);
135  progress_lay->addWidget(d->m_progressBar, 100);
136  progress_lay->addWidget(d->m_cancelBtn, 0);
137  d->m_activityFrame->hide();
138 
139  d->m_zInBtn = new QToolButton(this);
140  d->m_zInBtn->setAutoRaise(true);
141  d->m_zInBtn->setIcon(KIcon("zoom-in"));
142  d->m_zInBtn->setToolTip(i18n("Zoom In"));
143  connect(d->m_zInBtn, SIGNAL(clicked()), d->m_previewViewer, SLOT(zoomIn()));
144 
145  d->m_zOutBtn = new QToolButton(this);
146  d->m_zOutBtn->setAutoRaise(true);
147  d->m_zOutBtn->setIcon(KIcon("zoom-out"));
148  d->m_zOutBtn->setToolTip(i18n("Zoom Out"));
149  connect(d->m_zOutBtn, SIGNAL(clicked()), d->m_previewViewer, SLOT(zoomOut()));
150 
151  d->m_zSelBtn = new QToolButton(this);
152  d->m_zSelBtn->setAutoRaise(true);
153  d->m_zSelBtn->setIcon(KIcon("zoom-fit-best"));
154  d->m_zSelBtn->setToolTip(i18n("Zoom to Selection"));
155  connect(d->m_zSelBtn, SIGNAL(clicked()), d->m_previewViewer, SLOT(zoomSel()));
156 
157  d->m_zFitBtn = new QToolButton(this);
158  d->m_zFitBtn->setAutoRaise(true);
159  d->m_zFitBtn->setIcon(KIcon("document-preview"));
160  d->m_zFitBtn->setToolTip(i18n("Zoom to Fit"));
161  connect(d->m_zFitBtn, SIGNAL(clicked()), d->m_previewViewer, SLOT(zoom2Fit()));
162 
163  d->m_clearSelBtn = new QToolButton(this);
164  d->m_clearSelBtn->setAutoRaise(true);
165  d->m_clearSelBtn->setIcon(KIcon("edit-clear"));
166  d->m_clearSelBtn->setToolTip(i18n("Clear Selections"));
167  connect(d->m_clearSelBtn, SIGNAL(clicked()), d->m_previewViewer, SLOT(clearSelections()));
168 
169  d->m_prevBtn = new KPushButton(this);
170  d->m_prevBtn->setIcon(KIcon("document-import"));
171  d->m_prevBtn->setToolTip(i18n("Scan Preview Image"));
172  d->m_prevBtn->setText(i18nc("Preview button text", "Preview"));
173  connect(d->m_prevBtn, SIGNAL(clicked()), d, SLOT(startPreviewScan()));
174 
175  d->m_scanBtn = new KPushButton(this);
176  d->m_scanBtn->setIcon(KIcon("document-save"));
177  d->m_scanBtn->setToolTip(i18n("Scan Final Image"));
178  d->m_scanBtn->setText(i18nc("Final scan button text", "Scan"));
179  d->m_scanBtn->setFocus(Qt::OtherFocusReason);
180  connect(d->m_scanBtn, SIGNAL(clicked()), d, SLOT(startFinalScan()));
181 
182  d->m_btnFrame = new QWidget;
183  QHBoxLayout *btn_lay = new QHBoxLayout(d->m_btnFrame);
184  btn_lay->setContentsMargins(0,0,0,0);
185  btn_lay->addWidget(d->m_zInBtn);
186  btn_lay->addWidget(d->m_zOutBtn);
187  btn_lay->addWidget(d->m_zSelBtn);
188  btn_lay->addWidget(d->m_zFitBtn);
189  btn_lay->addWidget(d->m_clearSelBtn);
190  btn_lay->addStretch(100);
191  btn_lay->addWidget(d->m_prevBtn);
192  btn_lay->addWidget(d->m_scanBtn);
193 
194  // calculate the height of the waiting/scanning/buttons frames to avoid jumpiness.
195  int minHeight = d->m_btnFrame->sizeHint().height();
196  if (d->m_activityFrame->sizeHint().height() > minHeight) minHeight = d->m_activityFrame->sizeHint().height();
197  if (d->m_warmingUp->sizeHint().height() > minHeight) minHeight = d->m_warmingUp->sizeHint().height();
198  d->m_btnFrame->setMinimumHeight(minHeight);
199  d->m_activityFrame->setMinimumHeight(minHeight);
200  d->m_warmingUp->setMinimumHeight(minHeight);
201 
202  d->m_previewFrame = new QWidget;
203  QVBoxLayout *preview_layout = new QVBoxLayout(d->m_previewFrame);
204  preview_layout->setContentsMargins(0,0,0,0);
205  preview_layout->addWidget(d->m_previewViewer, 100);
206  preview_layout->addWidget(d->m_warmingUp, 0);
207  preview_layout->addWidget(d->m_activityFrame, 0);
208  preview_layout->addWidget(d->m_btnFrame, 0);
209 
210  // Create Options Widget
211  d->m_optsTabWidget = new KTabWidget;
212 
213  // Add the basic options tab
214  d->m_basicScrollA = new QScrollArea;
215  d->m_basicScrollA->setWidgetResizable(true);
216  d->m_basicScrollA->setFrameShape(QFrame::NoFrame);
217  d->m_optsTabWidget->addTab(d->m_basicScrollA, i18n("Basic Options"));
218 
219  // Add the other options tab
220  d->m_otherScrollA = new QScrollArea;
221  d->m_otherScrollA->setWidgetResizable(true);
222  d->m_otherScrollA->setFrameShape(QFrame::NoFrame);
223  d->m_optsTabWidget->addTab(d->m_otherScrollA, i18n("Scanner Specific Options"));
224 
225 
226  d->m_splitter = new QSplitter(this);
227  d->m_splitter->addWidget(d->m_optsTabWidget);
228  d->m_splitter->setStretchFactor(0,0);
229  d->m_splitter->addWidget(d->m_previewFrame);
230  d->m_splitter->setStretchFactor(1,100);
231 
232  d->m_optionsCollapser = new SplitterCollapser(d->m_splitter, d->m_optsTabWidget);
233 
234  QHBoxLayout *base_layout = new QHBoxLayout(this);
235  base_layout->addWidget(d->m_splitter);
236  base_layout->setContentsMargins(0,0,0,0);
237 
238  // disable the interface in case no device is opened.
239  d->m_optsTabWidget->setDisabled(true);
240  d->m_previewViewer->setDisabled(true);
241  d->m_btnFrame->setDisabled(true);
242 
243 }
244 
245 KSaneWidget::~KSaneWidget()
246 {
247  while (!closeDevice()) usleep(1000);
248  // wait for any thread to exit
249 
250  s_objectMutex.lock();
251  s_objectCount--;
252  if (s_objectCount <= 0) {
253  // only delete the find-devices and authorization singletons and call sane_exit
254  // if this is the last instance
255  delete d->m_findDevThread;
256  delete d->m_auth;
257  sane_exit();
258  }
259  s_objectMutex.unlock();
260  delete d;
261 }
262 
263 QString KSaneWidget::vendor() const
264 {
265  d->m_findDevThread->wait();
266  d->devListUpdated(); // this is just a wrapped if (m_vendor.isEmpty()) statement if the vendor is known
267  // devListUpdated here is to ensure that we do not come in between finished and the devListUpdated slot
268 
269  return d->m_vendor;
270 }
271 QString KSaneWidget::make() const
272 {
273  return vendor();
274 }
275 QString KSaneWidget::model() const
276 {
277  d->m_findDevThread->wait();
278  d->devListUpdated(); // this is just a wrapped if (m_vendor.isEmpty()) statement if the vendor is known
279  // devListUpdated here is to ensure that we do not come in between finished and the devListUpdated slot
280 
281  return d->m_model;
282 }
283 
284 QString KSaneWidget::selectDevice(QWidget* parent)
285 {
286  QString selected_name;
287  QPointer<KSaneDeviceDialog> sel = new KSaneDeviceDialog(parent);
288 
289  // sel.setDefault(prev_backend); // set default scanner - perhaps application using libksane should remember that
290  if(sel->exec() == KDialog::Accepted) {
291  selected_name = sel->getSelectedName();
292  }
293  delete sel;
294  return selected_name;
295 }
296 
297 void KSaneWidget::initGetDeviceList() const
298 {
299  // update the device list if needed to get the vendor and model info
300  if (d->m_findDevThread->devicesList().size() == 0) {
301  //kDebug() << "initGetDeviceList() starting thread...";
302  d->m_findDevThread->start();
303  }
304  else {
305  //kDebug() << "initGetDeviceList() have existing data...";
306  d->signalDevListUpdate();
307  }
308 }
309 
310 bool KSaneWidget::openDevice(const QString &deviceName)
311 {
312  int i=0;
313  const SANE_Option_Descriptor *optDesc;
314  SANE_Status status;
315  SANE_Word numSaneOptions;
316  SANE_Int res;
317  KPasswordDialog *dlg;
318  KWallet::Wallet *saneWallet;
319  QString myFolderName("ksane");
320  QMap<QString, QString> wallet_entry;
321 
322  if (d->m_saneHandle != 0) {
323  // this KSaneWidget already has an open device
324  return false;
325  }
326 
327  // don't bother trying to open if the device string is empty
328  if (deviceName.isEmpty()) {
329  return false;
330  }
331  // save the device name
332  d->m_devName = deviceName;
333 
334  // Try to open the device
335  status = sane_open(deviceName.toLatin1(), &d->m_saneHandle);
336 
337  bool password_dialog_ok = true;
338 
339  // prepare wallet for authentication and create password dialog
340  if(status == SANE_STATUS_ACCESS_DENIED) {
341  saneWallet = KWallet::Wallet::openWallet(KWallet::Wallet::LocalWallet(), winId() );
342 
343  if(saneWallet) {
344  dlg = new KPasswordDialog(this, KPasswordDialog::ShowUsernameLine | KPasswordDialog::ShowKeepPassword);
345  if(!saneWallet->hasFolder(myFolderName)) {
346  saneWallet->createFolder(myFolderName);
347  }
348  saneWallet->setFolder(myFolderName);
349  saneWallet->readMap(deviceName.toLatin1(), wallet_entry);
350  if(!wallet_entry.empty() || true) {
351  dlg->setUsername( wallet_entry["username"] );
352  dlg->setPassword( wallet_entry["password"] );
353  dlg->setKeepPassword( true );
354  }
355  } else {
356  dlg = new KPasswordDialog(this, KPasswordDialog::ShowUsernameLine);
357  }
358  dlg->setPrompt(i18n("Authentication required for resource: %1", deviceName ) );
359 
360  }
361 
362  // sane_open failed due to insufficient authorization
363  // retry opening device with user provided data assisted with kwallet records
364  while (status == SANE_STATUS_ACCESS_DENIED) {
365 
366  password_dialog_ok = dlg->exec();
367  if(!password_dialog_ok) {
368  delete dlg;
369  d->m_devName.clear();
370  return false; //the user canceled
371  }
372 
373  // add/update the device user-name and password for authentication
374  d->m_auth->setDeviceAuth(d->m_devName, dlg->username(), dlg->password());
375 
376  status = sane_open(deviceName.toLatin1(), &d->m_saneHandle);
377 
378  // store password in wallet on successful authentication
379  if(dlg->keepPassword() && status != SANE_STATUS_ACCESS_DENIED) {
380  QMap<QString, QString> entry;
381  entry["username"] = dlg->username().toUtf8();
382  entry["password"] = dlg->password().toUtf8();
383  if(saneWallet) {
384  saneWallet->writeMap(deviceName.toLatin1(), entry);
385  }
386  }
387  }
388 
389  if (status != SANE_STATUS_GOOD) {
390  kDebug() << "sane_open(\"" << deviceName << "\", &handle) failed! status = " << sane_strstatus(status);
391  d->m_auth->clearDeviceAuth(d->m_devName);
392  d->m_devName.clear();
393  return false;
394  }
395 
396  // update the device list if needed to get the vendor and model info
397  if (d->m_findDevThread->devicesList().size() == 0) {
398  d->m_findDevThread->start();
399  }
400  else {
401  // use the "old" existing list
402  d->devListUpdated();
403  // if m_vendor is not updated it means that the list needs to be updated.
404  if (d->m_vendor.isEmpty()) {
405  d->m_findDevThread->start();
406  }
407  }
408 
409  // Read the options (start with option 0 the number of parameters)
410  optDesc = sane_get_option_descriptor(d->m_saneHandle, 0);
411  if (optDesc == 0) {
412  d->m_auth->clearDeviceAuth(d->m_devName);
413  d->m_devName.clear();
414  return false;
415  }
416  QVarLengthArray<char> data(optDesc->size);
417  status = sane_control_option(d->m_saneHandle, 0, SANE_ACTION_GET_VALUE, data.data(), &res);
418  if (status != SANE_STATUS_GOOD) {
419  d->m_auth->clearDeviceAuth(d->m_devName);
420  d->m_devName.clear();
421  return false;
422  }
423  numSaneOptions = *reinterpret_cast<SANE_Word*>(data.data());
424 
425  // read the rest of the options
426  for (i=1; i<numSaneOptions; ++i) {
427  switch (KSaneOption::optionType(sane_get_option_descriptor(d->m_saneHandle, i))) {
428  case KSaneOption::TYPE_DETECT_FAIL:
429  d->m_optList.append(new KSaneOption(d->m_saneHandle, i));
430  break;
431  case KSaneOption::TYPE_CHECKBOX:
432  d->m_optList.append(new KSaneOptCheckBox(d->m_saneHandle, i));
433  break;
434  case KSaneOption::TYPE_SLIDER:
435  d->m_optList.append(new KSaneOptSlider(d->m_saneHandle, i));
436  break;
437  case KSaneOption::TYPE_F_SLIDER:
438  d->m_optList.append(new KSaneOptFSlider(d->m_saneHandle, i));
439  break;
440  case KSaneOption::TYPE_COMBO:
441  d->m_optList.append(new KSaneOptCombo(d->m_saneHandle, i));
442  break;
443  case KSaneOption::TYPE_ENTRY:
444  d->m_optList.append(new KSaneOptEntry(d->m_saneHandle, i));
445  break;
446  case KSaneOption::TYPE_GAMMA:
447  d->m_optList.append(new KSaneOptGamma(d->m_saneHandle, i));
448  break;
449  case KSaneOption::TYPE_BUTTON:
450  d->m_optList.append(new KSaneOptButton(d->m_saneHandle, i));
451  break;
452  }
453  }
454 
455  // do the connections of the option parameters
456  for (i=1; i<d->m_optList.size(); ++i) {
457  //kDebug() << d->m_optList.at(i)->name();
458  connect (d->m_optList.at(i), SIGNAL(optsNeedReload()), d, SLOT(optReload()));
459  connect (d->m_optList.at(i), SIGNAL(valsNeedReload()), d, SLOT(scheduleValReload()));
460 
461  if (d->m_optList.at(i)->needsPolling()) {
462  //kDebug() << d->m_optList.at(i)->name() << " needs polling";
463  d->m_pollList.append(d->m_optList.at(i));
464  KSaneOptCheckBox *buttonOption = qobject_cast<KSaneOptCheckBox *>(d->m_optList.at(i));
465  if (buttonOption) {
466  connect(buttonOption, SIGNAL(buttonPressed(QString,QString,bool)),
467  this, SIGNAL(buttonPressed(QString,QString,bool)));
468  }
469  }
470  }
471 
472  // start polling the poll options
473  if (d->m_pollList.size() > 0) {
474  d->m_optionPollTmr.start();
475  }
476 
477  // Create the preview thread
478  d->m_previewThread = new KSanePreviewThread(d->m_saneHandle, &d->m_previewImg);
479  connect(d->m_previewThread, SIGNAL(finished()), d, SLOT(previewScanDone()));
480 
481  // Create the read thread
482  d->m_scanThread = new KSaneScanThread(d->m_saneHandle, &d->m_scanData);
483  connect(d->m_scanThread, SIGNAL(finished()), d, SLOT(oneFinalScanDone()));
484 
485  // Create the options interface
486  d->createOptInterface();
487 
488  // try to set KSaneWidget default values
489  d->setDefaultValues();
490 
491  // Enable the interface
492  d->m_optsTabWidget->setDisabled(false);
493  d->m_previewViewer->setDisabled(false);
494  d->m_btnFrame->setDisabled(false);
495 
496  // estimate the preview size and create an empty image
497  // this is done so that you can select scan area without
498  // having to scan a preview.
499  d->updatePreviewSize();
500  QTimer::singleShot(1000, d->m_previewViewer, SLOT(zoom2Fit()));
501  return true;
502 }
503 
504 
505 bool KSaneWidget::closeDevice()
506 {
507  if (!d->m_saneHandle) {
508  return true;
509  }
510 
511  if (d->m_scanThread->isRunning()) {
512  d->m_scanThread->cancelScan();
513  d->m_closeDevicePending = true;
514  return false;
515  }
516 
517  if (d->m_previewThread->isRunning()) {
518  d->m_previewThread->cancelScan();
519  d->m_closeDevicePending = true;
520  return false;
521  }
522 
523  d->m_auth->clearDeviceAuth(d->m_devName);
524  // else
525  sane_close(d->m_saneHandle);
526  d->m_saneHandle = 0;
527  d->clearDeviceOptions();
528 
529  // disable the interface until a new device is opened.
530  d->m_optsTabWidget->setDisabled(true);
531  d->m_previewViewer->setDisabled(true);
532  d->m_btnFrame->setDisabled(true);
533 
534  return true;
535 }
536 
537 #define inc_pixel(x,y,ppl) { x++; if (x>=ppl) { y++; x=0;} }
538 
539 QImage KSaneWidget::toQImageSilent(const QByteArray &data,
540  int width,
541  int height,
542  int bytes_per_line,
543  ImageFormat format)
544 {
545  QImage img;
546  int j=0;
547  QVector<QRgb> table;
548  QRgb *imgLine;
549 
550  switch (format)
551  {
552  case FormatBlackWhite:
553  img = QImage((uchar*)data.data(),
554  width,
555  height,
556  bytes_per_line,
557  QImage::Format_Mono);
558  // The color table must be set
559  table.append(0xFFFFFFFF);
560  table.append(0xFF000000);
561  img.setColorTable(table);
562  break;
563 
564  case FormatGrayScale8:
565  {
566  img = QImage(width, height, QImage::Format_RGB32);
567  int dI = 0;
568  for (int i=0; (i<img.height() && dI<data.size()); i++) {
569  imgLine = reinterpret_cast<QRgb*>(img.scanLine(i));
570  for (j=0; (j<img.width() && dI<data.size()); j++) {
571  imgLine[j] = qRgb(data[dI], data[dI], data[dI]);
572  dI++;
573  }
574  }
575  break;
576  }
577  case FormatGrayScale16:
578  {
579  img = QImage(width, height, QImage::Format_RGB32);
580  int dI = 1;
581  for (int i=0; (i<img.height() && dI<data.size()); i++) {
582  imgLine = reinterpret_cast<QRgb*>(img.scanLine(i));
583  for (j=0; (j<img.width() && dI<data.size()); j++) {
584  imgLine[j] = qRgb(data[dI], data[dI], data[dI]);
585  dI+=2;
586  }
587  }
588  break;
589  }
590  case FormatRGB_8_C:
591  {
592  img = QImage(width, height, QImage::Format_RGB32);
593  int dI = 0;
594  for (int i=0; (i<img.height() && dI<data.size()); i++) {
595  imgLine = reinterpret_cast<QRgb*>(img.scanLine(i));
596  for (j=0; (j<img.width() && dI<data.size()); j++) {
597  imgLine[j] = qRgb(data[dI], data[dI+1], data[dI+2]);
598  dI+=3;
599  }
600  }
601  break;
602  }
603  case FormatRGB_16_C:
604  {
605  img = QImage(width, height, QImage::Format_RGB32);
606  int dI = 1;
607  for (int i=0; (i<img.height() && dI<data.size()); i++) {
608  imgLine = reinterpret_cast<QRgb*>(img.scanLine(i));
609  for (j=0; (j<img.width() && dI<data.size()); j++) {
610  imgLine[j] = qRgb(data[dI], data[dI+2], data[dI+4]);
611  dI+=6;
612  }
613  }
614  break;
615  }
616  case FormatNone:
617  default:
618  kDebug() << "Unsupported conversion";
619  break;
620  }
621  float dpm = currentDPI() * (1000.0 / 25.4);
622  img.setDotsPerMeterX(dpm);
623  img.setDotsPerMeterY(dpm);
624  return img;
625 }
626 
627 QImage KSaneWidget::toQImage(const QByteArray &data,
628  int width,
629  int height,
630  int bytes_per_line,
631  ImageFormat format)
632 {
633 
634  if ((format == FormatRGB_16_C) || (format == FormatGrayScale16)) {
635  d->alertUser(KSaneWidget::ErrorGeneral, i18n("The image data contained 16 bits per color, "
636  "but the color depth has been truncated to 8 bits per color."));
637  }
638  return toQImageSilent(data, width, height, bytes_per_line, format);
639 }
640 
641 void KSaneWidget::scanFinal()
642 {
643  if (d->m_btnFrame->isEnabled()) {
644  d->startFinalScan();
645  }
646  else {
647  // if the button frame is disabled, there is no open device to scan from
648  emit scanDone(KSaneWidget::ErrorGeneral, "");
649  }
650 }
651 
652 void KSaneWidget::scanCancel()
653 {
654  if (d->m_scanThread->isRunning()) {
655  d->m_scanThread->cancelScan();
656  }
657 
658  if (d->m_previewThread->isRunning()) {
659  d->m_previewThread->cancelScan();
660  }
661 }
662 
663 void KSaneWidget::setPreviewResolution(float dpi)
664 {
665  d->m_previewDPI = dpi;
666 }
667 
668 void KSaneWidget::getOptVals(QMap <QString, QString> &opts)
669 {
670  KSaneOption *option;
671  opts.clear();
672  QString tmp;
673 
674  for (int i=1; i<d->m_optList.size(); i++) {
675  option = d->m_optList.at(i);
676  if (option->getValue(tmp)) {
677  opts[option->name()] = tmp;
678  }
679  }
680  // Special handling for non sane option
681  opts[InvetColorsOption] = d->m_invertColors->isChecked() ? "true" : "false";
682 }
683 
684 bool KSaneWidget::getOptVal(const QString &optname, QString &value)
685 {
686  KSaneOption *option;
687 
688  if ((option = d->getOption(optname)) != 0) {
689  return option->getValue(value);
690  }
691  // Special handling for non sane option
692  if (optname == InvetColorsOption) {
693  value = d->m_invertColors->isChecked() ? "true" : "false";
694  return true;
695  }
696  return false;
697 }
698 
699 int KSaneWidget::setOptVals(const QMap <QString, QString> &opts)
700 {
701  QString tmp;
702  int i;
703  int ret=0;
704 
705  for (i=0; i<d->m_optList.size(); i++) {
706  if (opts.contains(d->m_optList.at(i)->name())) {
707  tmp = opts[d->m_optList.at(i)->name()];
708  if (d->m_optList.at(i)->setValue(tmp) == false) {
709  ret++;
710  }
711  }
712  }
713  if ((d->m_splitGamChB) &&
714  (d->m_optGamR) &&
715  (d->m_optGamG) &&
716  (d->m_optGamB))
717  {
718  // check if the current gamma values are identical. if they are identical,
719  // uncheck the "Separate color intensity tables" checkbox
720  QString redGamma;
721  QString greenGamma;
722  QString blueGamma;
723  d->m_optGamR->getValue(redGamma);
724  d->m_optGamG->getValue(greenGamma);
725  d->m_optGamB->getValue(blueGamma);
726  if ((redGamma == greenGamma) && (greenGamma == blueGamma)) {
727  d->m_splitGamChB->setChecked(false);
728  // set the values to the common gamma widget
729  d->m_commonGamma->setValues(redGamma);
730  }
731  else {
732  d->m_splitGamChB->setChecked(true);
733  }
734  }
735 
736  // special handling for non-sane option
737  if (opts.contains(InvetColorsOption)) {
738  tmp = opts[InvetColorsOption];
739  if ((tmp.compare("true", Qt::CaseInsensitive) == 0) ||
740  (tmp.compare("1") == 0))
741  {
742  d->m_invertColors->setChecked(true);
743  }
744  else {
745  d->m_invertColors->setChecked(false);
746  }
747  }
748  return ret;
749 }
750 
751 bool KSaneWidget::setOptVal(const QString &option, const QString &value)
752 {
753  KSaneOption *opt;
754 
755  if ((opt = d->getOption(option)) != 0) {
756  if (opt->setValue(value)) {
757  if ((d->m_splitGamChB) &&
758  (d->m_optGamR) &&
759  (d->m_optGamG) &&
760  (d->m_optGamB) &&
761  ((opt == d->m_optGamR) ||
762  (opt == d->m_optGamG) ||
763  (opt == d->m_optGamB)))
764  {
765  // check if the current gamma values are identical. if they are identical,
766  // uncheck the "Separate color intensity tables" checkbox
767  QString redGamma;
768  QString greenGamma;
769  QString blueGamma;
770  d->m_optGamR->getValue(redGamma);
771  d->m_optGamG->getValue(greenGamma);
772  d->m_optGamB->getValue(blueGamma);
773  if ((redGamma == greenGamma) && (greenGamma == blueGamma)) {
774  d->m_splitGamChB->setChecked(false);
775  // set the values to the common gamma widget
776  d->m_commonGamma->setValues(redGamma);
777  }
778  else {
779  d->m_splitGamChB->setChecked(true);
780  }
781  }
782  return true;
783  }
784  }
785 
786  // special handling for non-sane option
787  if (option == InvetColorsOption) {
788  if ((value.compare("true", Qt::CaseInsensitive) == 0) ||
789  (value.compare("1") == 0))
790  {
791  d->m_invertColors->setChecked(true);
792  }
793  else {
794  d->m_invertColors->setChecked(false);
795  }
796  return true;
797  }
798 
799  return false;
800 }
801 
802 void KSaneWidget::setScanButtonText(const QString &scanLabel)
803 {
804  if (d->m_scanBtn == 0) {
805  kError() << "setScanButtonText was called before KSaneWidget was initialized";
806  return;
807  }
808  d->m_scanBtn->setText(scanLabel);
809 }
810 
811 void KSaneWidget::setPreviewButtonText(const QString &previewLabel)
812 {
813  if (d->m_scanBtn == 0) {
814  kError() << "setPreviewButtonText was called before KSaneWidget was initialized";
815  return;
816  }
817  d->m_prevBtn->setText(previewLabel);
818 }
819 
820 void KSaneWidget::enableAutoSelect(bool enable)
821 {
822  d->m_autoSelect = enable;
823 }
824 
825 float KSaneWidget::currentDPI()
826 {
827  if (d->m_optRes) {
828  float value;
829  if (d->m_optRes->getValue(value)) {
830  return value;
831  }
832  }
833  return 0.0;
834 }
835 
836 float KSaneWidget::scanAreaWidth()
837 {
838  float result = 0.0;
839  if (d->m_optBrX) {
840  if (d->m_optBrX->getUnit() == SANE_UNIT_PIXEL) {
841  d->m_optBrX->getMaxValue(result);
842  result = result / currentDPI() / 25.4;
843  }
844  else if (d->m_optBrX->getUnit() == SANE_UNIT_MM) {
845  d->m_optBrX->getMaxValue(result);
846  }
847  }
848  return result;
849 }
850 
851 float KSaneWidget::scanAreaHeight()
852 {
853  float result = 0.0;
854  if (d->m_optBrY) {
855  if (d->m_optBrY->getUnit() == SANE_UNIT_PIXEL) {
856  d->m_optBrY->getMaxValue(result);
857  result = result / currentDPI() / 25.4;
858  }
859  else if (d->m_optBrY->getUnit() == SANE_UNIT_MM) {
860  d->m_optBrY->getMaxValue(result);
861  }
862  }
863  return result;
864 }
865 
866 void KSaneWidget::setSelection(QPointF topLeft, QPointF bottomRight)
867 {
868  if (!d->m_optBrX || !d->m_optBrY || !d->m_optTlX || !d->m_optTlY) {
869  return;
870  }
871  float xmax, ymax;
872  d->m_optBrX->getMaxValue(xmax);
873  d->m_optBrY->getMaxValue(ymax);
874  if (topLeft.x() < 0.0 || topLeft.y() < 0.0 || bottomRight.x() < 0.0 || bottomRight.y() < 0.0) {
875  d->m_previewViewer->clearActiveSelection();
876  d->m_optTlX->setValue(0.0);
877  d->m_optTlY->setValue(0.0);
878  d->m_optBrX->setValue(xmax);
879  d->m_optBrY->setValue(ymax);
880  }
881 
882  if (d->m_optBrY->getUnit() == SANE_UNIT_MM) {
883  // clear selection if values are out of bounds
884  if (topLeft.x() > xmax || topLeft.y() > ymax || bottomRight.x() > xmax || bottomRight.y() > ymax) {
885  d->m_previewViewer->clearActiveSelection();
886  d->m_optTlX->setValue(0.0);
887  d->m_optTlY->setValue(0.0);
888  d->m_optBrX->setValue(xmax);
889  d->m_optBrY->setValue(ymax);
890  }
891  d->m_previewViewer->setSelection(topLeft.x(), topLeft.y(), bottomRight.x(), bottomRight.y());
892  d->m_optTlX->setValue(topLeft.x());
893  d->m_optTlY->setValue(topLeft.y());
894  d->m_optBrX->setValue(bottomRight.x());
895  d->m_optBrY->setValue(bottomRight.y());
896  }
897  else if (d->m_optBrY->getUnit() == SANE_UNIT_PIXEL) {
898  const float mmperinch = 25.4;
899  const float dpi = currentDPI();
900  const float m = dpi / mmperinch;
901  if (m*topLeft.x() > xmax || m*topLeft.y() > ymax || m*bottomRight.x() > xmax || m*bottomRight.y() > ymax) {
902  d->m_previewViewer->clearActiveSelection();
903  d->m_optTlX->setValue(0.0);
904  d->m_optTlY->setValue(0.0);
905  d->m_optBrX->setValue(xmax);
906  d->m_optBrY->setValue(ymax);
907  }
908  d->m_previewViewer->setSelection(m*topLeft.x(), m*topLeft.y(), m*bottomRight.x(), m*bottomRight.y());
909  d->m_optTlX->setValue(m*topLeft.x());
910  d->m_optTlY->setValue(m*topLeft.y());
911  d->m_optBrX->setValue(m*bottomRight.x());
912  d->m_optBrY->setValue(m*bottomRight.y());
913  }
914 }
915 
916 void KSaneWidget::setOptionsCollapsed(bool collapse)
917 {
918  if (collapse) {
919  QTimer::singleShot(0, d->m_optionsCollapser, SLOT(slotCollapse()));
920  }
921  else {
922  QTimer::singleShot(0, d->m_optionsCollapser, SLOT(slotRestore()));
923  }
924 }
925 
926 void KSaneWidget::setScanButtonHidden(bool hidden)
927 {
928  d->m_scanBtn->setHidden(hidden);
929 }
930 
931 } // NameSpace KSaneIface
KSaneIface::KSaneWidget::toQImageSilent
QImage toQImageSilent(const QByteArray &data, int width, int height, int bytes_per_line, ImageFormat format)
This is a convenience method that can be used to create a QImage from the image data returned by the ...
Definition: ksane_widget.cpp:539
QImage::scanLine
uchar * scanLine(int i)
KSaneIface::KSaneWidgetPrivate::m_readValsTmr
QTimer m_readValsTmr
Definition: ksane_widget_private.h:187
QTimer::setInterval
void setInterval(int msec)
KSaneIface::KSaneWidget::ImageFormat
ImageFormat
This enumeration describes the type of the returned data.
Definition: ksane.h:56
QProgressBar
KSaneIface::KSaneWidgetPrivate::m_zOutBtn
QToolButton * m_zOutBtn
Definition: ksane_widget_private.h:129
KSaneIface::KSaneWidgetPrivate::m_autoSelect
bool m_autoSelect
Definition: ksane_widget_private.h:176
KSaneIface::KSaneWidgetPrivate::m_optGamG
KSaneOption * m_optGamG
Definition: ksane_widget_private.h:164
KSaneIface::KSaneWidgetPrivate::m_cancelBtn
KPushButton * m_cancelBtn
Definition: ksane_widget_private.h:139
QMutex
KSaneIface::KSaneWidgetPrivate::m_activityFrame
QWidget * m_activityFrame
Definition: ksane_widget_private.h:136
QWidget
QProgressBar::setMaximum
void setMaximum(int maximum)
QImage::setDotsPerMeterX
void setDotsPerMeterX(int x)
QImage::setDotsPerMeterY
void setDotsPerMeterY(int y)
KSaneIface::KSaneOptFSlider
Definition: ksane_opt_fslider.h:38
KSaneIface::KSaneWidget::buttonPressed
void buttonPressed(const QString &optionName, const QString &optionLabel, bool pressed)
This Signal is emitted when a hardware button is pressed.
KSaneIface::KSaneWidget::scanCancel
void scanCancel()
This method can be used to cancel a scan or prevent an automatic new scan.
Definition: ksane_widget.cpp:652
KSaneIface::KSaneWidgetPrivate::m_zInBtn
QToolButton * m_zInBtn
Definition: ksane_widget_private.h:128
QLayout::setContentsMargins
void setContentsMargins(int left, int top, int right, int bottom)
KSaneIface::KSaneOption::TYPE_GAMMA
Definition: ksane_option.h:63
KSaneIface::KSaneAuth::clearDeviceAuth
void clearDeviceAuth(const QString &resource)
Definition: ksane_auth.cpp:97
KSaneIface::KSaneWidget::initGetDeviceList
void initGetDeviceList() const
Get the list of available scanning devices.
Definition: ksane_widget.cpp:297
KSaneIface::KSaneOption::optionType
static KSaneOptType optionType(const SANE_Option_Descriptor *optDesc)
Definition: ksane_option.cpp:239
KSaneIface::KSaneWidgetPrivate::clearDeviceOptions
void clearDeviceOptions()
Definition: ksane_widget_private.cpp:97
KSaneIface::KSaneWidgetPrivate::m_optGamB
KSaneOption * m_optGamB
Definition: ksane_widget_private.h:165
QMap::contains
bool contains(const Key &key) const
KSaneIface::KSaneWidgetPrivate::m_zSelBtn
QToolButton * m_zSelBtn
Definition: ksane_widget_private.h:130
KSaneIface::KSaneWidgetPrivate::m_optList
QList< KSaneOption * > m_optList
Definition: ksane_widget_private.h:148
QMap::empty
bool empty() const
KSaneIface::KSaneWidget::setScanButtonText
void setScanButtonText(const QString &scanLabel)
This function sets the label on the final scan button.
Definition: ksane_widget.cpp:802
KSaneIface::KSaneWidget::KSaneWidget
KSaneWidget(QWidget *parent=0)
This constructor initializes the private class variables, but the widget is left empty.
Definition: ksane_widget.cpp:69
KSaneIface::KSaneWidget::model
QString model() const
This methos returns the model of the scanner.
Definition: ksane_widget.cpp:275
KSaneIface::LabeledCheckbox::setChecked
void setChecked(bool)
Definition: labeled_checkbox.cpp:52
QVector::append
void append(const T &value)
QByteArray
KSaneIface::SplitterCollapser
A button which appears on the side of a splitter handle and allows easy collapsing of the widget on t...
Definition: splittercollapser.h:41
QSplitter::setStretchFactor
void setStretchFactor(int index, int stretch)
KSaneIface::KSaneWidget::setOptionsCollapsed
void setOptionsCollapsed(bool collapse)
This function is used to programatically collapse/restore the options.
Definition: ksane_widget.cpp:916
ksane_opt_entry.h
KSaneIface::s_objectMutex
static QMutex s_objectMutex
Definition: ksane_widget.cpp:65
KSaneIface::KSaneScanThread
Definition: ksane_scan_thread.h:45
KSaneIface::KSaneWidgetPrivate::m_basicScrollA
QScrollArea * m_basicScrollA
Definition: ksane_widget_private.h:115
QFrame::setFrameShape
void setFrameShape(Shape)
KSaneIface::KSanePreviewThread::cancelScan
void cancelScan()
Definition: ksane_preview_thread.cpp:65
KSaneIface::KSaneWidgetPrivate::signalDevListUpdate
void signalDevListUpdate()
Definition: ksane_widget_private.cpp:159
KSaneIface::KSaneWidgetPrivate::m_optsTabWidget
KTabWidget * m_optsTabWidget
Definition: ksane_widget_private.h:114
KSaneIface::KSanePreviewThread
Definition: ksane_preview_thread.h:46
QMap
ksane_opt_slider.h
KSaneIface::KSaneOptSlider
Definition: ksane_opt_slider.h:38
QPointer
ksane.h
KSaneIface::KSaneOption::TYPE_F_SLIDER
Definition: ksane_option.h:60
ksane_option.h
QVarLengthArray
KSaneIface::KSaneWidgetPrivate::setDefaultValues
void setDefaultValues()
Definition: ksane_widget_private.cpp:488
QHBoxLayout
QLabel::setAlignment
void setAlignment(QFlags< Qt::AlignmentFlag >)
KSaneIface::KSaneWidget::scanAreaWidth
float scanAreaWidth()
This method returns the scan area's width in mm.
Definition: ksane_widget.cpp:836
QMutex::unlock
void unlock()
KSaneIface::KSaneWidgetPrivate::m_pollList
QList< KSaneOption * > m_pollList
Definition: ksane_widget_private.h:149
KSaneIface::KSaneOption::TYPE_COMBO
Definition: ksane_option.h:61
KSaneIface::LabeledCheckbox::isChecked
bool isChecked()
Definition: labeled_checkbox.cpp:57
KSaneIface::KSaneWidget::vendor
QString vendor() const
This method returns the vendor name of the scanner (Same as make).
Definition: ksane_widget.cpp:263
QMap::clear
void clear()
ksane_opt_combo.h
QAbstractButton::setIcon
void setIcon(const QIcon &icon)
KSaneIface::s_objectCount
static int s_objectCount
Definition: ksane_widget.cpp:64
KSaneIface::KSaneWidgetPrivate
Definition: ksane_widget_private.h:70
QSplitter::addWidget
void addWidget(QWidget *widget)
QPointF
QString::clear
void clear()
KSaneIface::LabeledGamma::setValues
void setValues(int bri, int con, int gam)
Definition: labeled_gamma.cpp:100
KSaneIface::KSaneAuth::setDeviceAuth
void setDeviceAuth(const QString &resource, const QString &username, const QString &password)
Definition: ksane_auth.cpp:75
KSaneIface::KSaneViewer::setSelection
void setSelection(float tl_x, float tl_y, float br_x, float br_y)
This function is used to set a selection without the user setting it.
Definition: ksane_viewer.cpp:281
QWidget::width
int width() const
KSaneIface::KSaneWidgetPrivate::m_prevBtn
KPushButton * m_prevBtn
Definition: ksane_widget_private.h:134
KSaneIface::KSaneOptEntry
Definition: ksane_opt_entry.h:38
QThread::start
void start(Priority priority)
KSaneIface::KSaneWidget::FormatBlackWhite
One bit per pixel 1 = black 0 = white.
Definition: ksane.h:58
KSaneIface::KSaneOptCombo
Definition: ksane_opt_combo.h:38
KSaneIface::KSaneWidget::scanFinal
void scanFinal()
This method can be used to start a scan (if no GUI is needed).
Definition: ksane_widget.cpp:641
QWidget::isEnabled
bool isEnabled() const
QBoxLayout::addWidget
void addWidget(QWidget *widget, int stretch, QFlags< Qt::AlignmentFlag > alignment)
QPointF::x
qreal x() const
QPointF::y
qreal y() const
KSaneIface::KSaneWidget::setPreviewButtonText
void setPreviewButtonText(const QString &previewLabel)
This function sets the label on the preview button.
Definition: ksane_widget.cpp:811
KSaneIface::KSaneWidgetPrivate::m_previewFrame
QWidget * m_previewFrame
Definition: ksane_widget_private.h:125
KSaneIface::KSaneOption::TYPE_SLIDER
Definition: ksane_option.h:59
KSaneIface::KSaneWidget::scanAreaHeight
float scanAreaHeight()
This method returns the scan area's height in mm.
Definition: ksane_widget.cpp:851
KSaneIface::KSaneWidgetPrivate::m_optTlY
KSaneOption * m_optTlY
Definition: ksane_widget_private.h:159
KSaneIface::KSaneWidgetPrivate::m_closeDevicePending
bool m_closeDevicePending
Definition: ksane_widget_private.h:181
KSaneIface::KSaneWidgetPrivate::m_previewThread
KSanePreviewThread * m_previewThread
Definition: ksane_widget_private.h:191
KSaneIface::KSaneWidgetPrivate::m_splitGamChB
LabeledCheckbox * m_splitGamChB
Definition: ksane_widget_private.h:166
KSaneIface::KSaneWidgetPrivate::m_splitter
QSplitter * m_splitter
Definition: ksane_widget_private.h:122
KSaneIface::KSaneWidgetPrivate::m_zFitBtn
QToolButton * m_zFitBtn
Definition: ksane_widget_private.h:131
QImage::width
int width() const
KSaneIface::KSaneOption::setValue
virtual bool setValue(float val)
Definition: ksane_option.cpp:199
KSaneIface::KSaneAuth::authorization
static void authorization(SANE_String_Const resource, SANE_Char *username, SANE_Char *password)
static function called by sane_open to get authorization from user
Definition: ksane_auth.cpp:109
KSaneIface::KSaneOption::TYPE_ENTRY
Definition: ksane_option.h:62
KSaneIface::KSaneWidget::~KSaneWidget
~KSaneWidget()
Standard destructor.
Definition: ksane_widget.cpp:245
ksane_widget_private.h
KSaneIface::KSaneWidgetPrivate::m_scanData
QByteArray m_scanData
Definition: ksane_widget_private.h:184
KSaneIface::KSaneWidget::FormatRGB_16_C
Every pixel consists of three colors in the order Read, Grean and Blue, with two bytes per color(no a...
Definition: ksane.h:64
KSaneIface::KSaneWidgetPrivate::m_previewImg
QImage m_previewImg
Definition: ksane_widget_private.h:174
KSaneIface::KSaneOption::TYPE_DETECT_FAIL
Definition: ksane_option.h:57
QString::isEmpty
bool isEmpty() const
KSaneIface::KSaneWidgetPrivate::startFinalScan
void startFinalScan()
Definition: ksane_widget_private.cpp:844
KSaneIface::KSaneWidgetPrivate::m_optionsCollapser
SplitterCollapser * m_optionsCollapser
Definition: ksane_widget_private.h:123
QVBoxLayout
KSaneIface::KSaneWidgetPrivate::m_optionPollTmr
QTimer m_optionPollTmr
Definition: ksane_widget_private.h:189
KSaneIface::KSaneOption::getMaxValue
virtual bool getMaxValue(float &max)
Definition: ksane_option.cpp:197
KSaneIface::KSaneWidget::setOptVal
bool setOptVal(const QString &optname, const QString &value)
This function writes one parameter value into a string.
Definition: ksane_widget.cpp:751
KSaneIface::KSaneOptGamma
Definition: ksane_opt_gamma.h:38
KSaneIface::KSaneWidget::currentDPI
float currentDPI()
This method returns the current resolution of the acquired image, in dots per inch.
Definition: ksane_widget.cpp:825
QWidget::winId
WId winId() const
QLabel::setText
void setText(const QString &)
QString
QWidget::hide
void hide()
KSaneIface::KSaneWidget::ErrorGeneral
The error string should contain an error message.
Definition: ksane.h:78
ksane_opt_button.h
QToolButton::setAutoRaise
void setAutoRaise(bool enable)
KSaneIface::KSaneWidget::enableAutoSelect
void enableAutoSelect(bool enable)
This function can be used to enable/disable automatic selections on previews.
Definition: ksane_widget.cpp:820
ksane_device_dialog.h
KSaneIface::KSaneOption
Definition: ksane_option.h:49
KSaneIface::KSaneOptButton
Definition: ksane_opt_button.h:38
KSaneIface::KSaneWidget::FormatNone
This enumeration value should never be returned to the user.
Definition: ksane.h:68
KSaneIface::KSaneWidgetPrivate::m_optGamR
KSaneOption * m_optGamR
Definition: ksane_widget_private.h:163
KSaneIface::KSaneWidgetPrivate::m_warmingUp
QLabel * m_warmingUp
Definition: ksane_widget_private.h:137
KSaneIface::KSaneWidget::setSelection
void setSelection(QPointF topLeft, QPointF bottomRight)
This method sets the selection according to the given points.
Definition: ksane_widget.cpp:866
KSaneIface::KSaneWidgetPrivate::m_optBrY
KSaneOption * m_optBrY
Definition: ksane_widget_private.h:161
KSaneIface::KSaneWidget::getOptVal
bool getOptVal(const QString &optname, QString &value)
This function reads one parameter value into a string.
Definition: ksane_widget.cpp:684
QToolButton
KSaneIface::KSaneViewer
Definition: ksane_viewer.h:37
KSaneIface::KSaneOption::getUnit
virtual int getUnit()
Definition: ksane_option.cpp:202
KSaneIface::KSaneWidgetPrivate::m_scanThread
KSaneScanThread * m_scanThread
Definition: ksane_widget_private.h:190
QMutex::lock
void lock()
QScrollArea::setWidgetResizable
void setWidgetResizable(bool resizable)
QThread::isRunning
bool isRunning() const
QWidget::sizeHint
sizeHint
KSaneIface::KSaneWidget::FormatGrayScale8
Grayscale with one byte per pixel 0 = black 255 = white.
Definition: ksane.h:59
KSaneIface::KSaneWidgetPrivate::m_progressBar
QProgressBar * m_progressBar
Definition: ksane_widget_private.h:138
KSaneIface::KSaneWidgetPrivate::m_optBrX
KSaneOption * m_optBrX
Definition: ksane_widget_private.h:160
QImage
KSaneIface::FindSaneDevicesThread::devicesList
const QList< KSaneWidget::DeviceInfo > devicesList() const
Definition: ksane_find_devices_thread.cpp:102
KSaneIface::KSaneWidgetPrivate::m_optRes
KSaneOption * m_optRes
Definition: ksane_widget_private.h:155
KSaneIface::KSaneWidget::setScanButtonHidden
void setScanButtonHidden(bool hidden)
This function is used hide/show the final scan button.
Definition: ksane_widget.cpp:926
QSplitter
QString::toLatin1
QByteArray toLatin1() const
KSaneIface::KSaneWidgetPrivate::m_previewDPI
float m_previewDPI
Definition: ksane_widget_private.h:173
QVector
KSaneIface::KSaneWidget::scanDone
void scanDone(int status, const QString &strStatus)
This signal is emitted when the scanning has ended.
KSaneIface::KSaneWidgetPrivate::m_previewViewer
KSaneViewer * m_previewViewer
Definition: ksane_widget_private.h:126
QThread::wait
bool wait(unsigned long time)
KSaneIface::KSaneWidget::selectDevice
QString selectDevice(QWidget *parent=0)
This helper method displays a dialog for selecting a scanner.
Definition: ksane_widget.cpp:284
QBoxLayout::addStretch
void addStretch(int stretch)
KSaneIface::KSaneWidgetPrivate::m_scanBtn
KPushButton * m_scanBtn
Definition: ksane_widget_private.h:133
KSaneIface::KSaneWidgetPrivate::devListUpdated
void devListUpdated()
Definition: ksane_widget_private.cpp:143
KSaneIface::KSaneWidgetPrivate::m_otherScrollA
QScrollArea * m_otherScrollA
Definition: ksane_widget_private.h:118
KSaneIface::KSaneWidget::FormatGrayScale16
Grayscale withtTwo bytes per pixel.
Definition: ksane.h:60
KSaneIface::KSaneOption::TYPE_CHECKBOX
Definition: ksane_option.h:58
KSaneIface::KSaneOption::TYPE_BUTTON
Definition: ksane_option.h:64
QWidget::QWidget
QWidget(QWidget *parent, QFlags< Qt::WindowType > f)
KSaneIface::KSaneWidgetPrivate::m_devName
QString m_devName
Definition: ksane_widget_private.h:143
KSaneIface::KSaneScanThread::cancelScan
void cancelScan()
Definition: ksane_scan_thread.cpp:66
KSaneIface::KSaneWidget::toQImage
QImage toQImage(const QByteArray &data, int width, int height, int bytes_per_line, ImageFormat format)
This is a convenience method that can be used to create a QImage from the image data returned by the ...
Definition: ksane_widget.cpp:627
QLabel::sizeHint
virtual QSize sizeHint() const
QSize::height
int height() const
QImage::setColorTable
void setColorTable(const QVector< QRgb > colors)
KSaneIface::KSaneWidget::make
QString make() const
This method returns the make name of the scanner.
Definition: ksane_widget.cpp:271
QWidget::setMinimumHeight
void setMinimumHeight(int minh)
QVarLengthArray::data
T * data()
QByteArray::data
char * data()
KSaneIface::KSaneWidget::setPreviewResolution
void setPreviewResolution(float dpi)
This function is used to set the preferred resolution for scanning the preview.
Definition: ksane_widget.cpp:663
KSaneIface::KSaneWidgetPrivate::alertUser
void alertUser(int type, const QString &strStatus)
Definition: ksane_widget_private.cpp:1109
KSaneIface::KSaneDeviceDialog
Definition: ksane_device_dialog.h:52
QTimer::start
void start(int msec)
KSaneIface::KSaneWidgetPrivate::m_findDevThread
FindSaneDevicesThread * m_findDevThread
Definition: ksane_widget_private.h:196
KSaneIface::InvetColorsOption
static const QString InvetColorsOption
Definition: ksane_widget.cpp:67
KSaneIface::KSaneWidgetPrivate::m_invertColors
LabeledCheckbox * m_invertColors
Definition: ksane_widget_private.h:120
QImage::height
int height() const
KSaneIface::KSaneViewer::clearActiveSelection
void clearActiveSelection()
Definition: ksane_viewer.cpp:485
QWidget::setAutoFillBackground
void setAutoFillBackground(bool enabled)
KSaneIface::KSaneWidget::setOptVals
int setOptVals(const QMap< QString, QString > &opts)
This method can be used to write many parameter values at once.
Definition: ksane_widget.cpp:699
KSaneIface::KSaneWidgetPrivate::m_model
QString m_model
Definition: ksane_widget_private.h:145
ksane_opt_checkbox.h
KSaneIface::KSaneWidgetPrivate::m_updProgressTmr
QTimer m_updProgressTmr
Definition: ksane_widget_private.h:188
KSaneIface::KSaneWidget::openDevice
bool openDevice(const QString &device_name)
This method opens the specified scanner device and adds the scan options to the KSane widget...
Definition: ksane_widget.cpp:310
KSaneIface::KSaneWidgetPrivate::m_vendor
QString m_vendor
Definition: ksane_widget_private.h:144
QWidget::setToolTip
void setToolTip(const QString &)
QWidget::setDisabled
void setDisabled(bool disable)
labeled_gamma.h
KSaneIface::KSaneWidget::getOptVals
void getOptVals(QMap< QString, QString > &opts)
This method reads the available parameters and their values and returns them in a QMap (Name...
Definition: ksane_widget.cpp:668
KSaneIface::KSaneWidgetPrivate::createOptInterface
void createOptInterface()
Definition: ksane_widget_private.cpp:231
KSaneIface::KSaneOptCheckBox
Definition: ksane_opt_checkbox.h:38
KSaneIface::KSaneWidgetPrivate::m_optTlX
KSaneOption * m_optTlX
Definition: ksane_widget_private.h:158
QWidget::setBackgroundRole
void setBackgroundRole(QPalette::ColorRole role)
QScrollArea
QByteArray::size
int size() const
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QLabel
QString::compare
int compare(const QString &other) const
KSaneIface::KSaneWidgetPrivate::m_auth
KSaneAuth * m_auth
Definition: ksane_widget_private.h:197
ksane_opt_gamma.h
ksane_opt_fslider.h
KSaneIface::KSaneWidgetPrivate::m_commonGamma
LabeledGamma * m_commonGamma
Definition: ksane_widget_private.h:167
QWidget::height
int height() const
KSaneIface::KSaneWidgetPrivate::m_btnFrame
QWidget * m_btnFrame
Definition: ksane_widget_private.h:127
KSaneIface::KSaneWidgetPrivate::updatePreviewSize
void updatePreviewSize()
Definition: ksane_widget_private.cpp:646
KSaneIface::KSaneOption::name
QString name()
Definition: ksane_option.cpp:120
KSaneIface::KSaneWidget::FormatRGB_8_C
Every pixel consists of three colors in the order Read, Grean and Blue, with one byte per color (no a...
Definition: ksane.h:62
KSaneIface::KSaneWidgetPrivate::m_clearSelBtn
QToolButton * m_clearSelBtn
Definition: ksane_widget_private.h:132
KSaneIface::KSaneWidgetPrivate::getOption
KSaneOption * getOption(const QString &name)
Definition: ksane_widget_private.cpp:220
KSaneIface::KSaneWidget::closeDevice
bool closeDevice()
This method closes the currently open scanner device.
Definition: ksane_widget.cpp:505
KSaneIface::KSaneOption::getValue
virtual bool getValue(float &val)
Definition: ksane_option.cpp:198
KSaneIface::KSaneWidgetPrivate::m_saneHandle
SANE_Handle m_saneHandle
Definition: ksane_widget_private.h:142
QTimer::setSingleShot
void setSingleShot(bool singleShot)
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:19:47 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

libs/libksane/libksane

Skip menu "libs/libksane/libksane"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdegraphics API Reference

Skip menu "kdegraphics API Reference"
  •     libkdcraw
  •     libkexiv2
  •     libkipi
  •     libksane
  • okular

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal