File indexing completed on 2022-09-27 16:37:10

0001 /*
0002     SPDX-FileCopyrightText: 2010-2018 Daniel Nicoletti <dantti12@gmail.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "PageChoosePrinters.h"
0008 #include "ui_PageChoosePrinters.h"
0009 
0010 #include <ClassListWidget.h>
0011 
0012 #include <KCupsRequest.h>
0013 #include <KLocalizedString>
0014 
0015 #include <QPainter>
0016 
0017 PageChoosePrinters::PageChoosePrinters(const QVariantHash &args, QWidget *parent) :
0018     GenericPage(parent),
0019     ui(new Ui::PageChoosePrinters)
0020 {
0021     ui->setupUi(this);
0022 
0023     // setup default options
0024     setWindowTitle(i18nc("@title:window", "Select a Printer to Add"));
0025     // loads the standard key icon
0026 
0027     const int printerSize = 128;
0028     const int overlaySize = 48;
0029 
0030     QPixmap printerIcon = QIcon::fromTheme(QStringLiteral("printer")).pixmap(printerSize);
0031     const QPixmap preferencesIcon = QIcon::fromTheme(QStringLiteral("preferences-other")).pixmap(overlaySize);
0032 
0033     QPainter painter(&printerIcon);
0034 
0035     // bottom right corner
0036     const QPoint startPoint = QPoint(printerSize - overlaySize - 2,
0037                                      printerSize - overlaySize - 2);
0038     painter.drawPixmap(startPoint, preferencesIcon);
0039     ui->printerL->setPixmap(printerIcon);
0040 
0041     connect(ui->membersLV, static_cast<void (ClassListWidget::*) (bool)>(&ClassListWidget::changed),
0042             this, &PageChoosePrinters::allowProceed);
0043 
0044     if (!args.isEmpty()) {
0045         setValues(args);
0046     }
0047 }
0048 
0049 PageChoosePrinters::~PageChoosePrinters()
0050 {
0051     delete ui;
0052 }
0053 
0054 void PageChoosePrinters::setValues(const QVariantHash &args)
0055 {
0056     if (m_args != args) {
0057         m_args = args;
0058     }
0059 }
0060 
0061 QVariantHash PageChoosePrinters::values() const
0062 {
0063     QVariantHash ret = m_args;
0064     ret[KCUPS_MEMBER_URIS] = ui->membersLV->currentSelected(true);
0065     return ret;
0066 }
0067 
0068 bool PageChoosePrinters::canProceed() const
0069 {
0070     return ui->membersLV->selectedPrinters().count() > 0;
0071 }
0072 
0073 #include "moc_PageChoosePrinters.cpp"