File indexing completed on 2025-01-19 05:06:22

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 QVariantMap &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, printerSize - overlaySize - 2);
0037     painter.drawPixmap(startPoint, preferencesIcon);
0038     ui->printerL->setPixmap(printerIcon);
0039 
0040     connect(ui->membersLV, &ClassListWidget::changed, this, &PageChoosePrinters::allowProceed);
0041 
0042     if (!args.isEmpty()) {
0043         setValues(args);
0044     }
0045 }
0046 
0047 PageChoosePrinters::~PageChoosePrinters()
0048 {
0049     delete ui;
0050 }
0051 
0052 void PageChoosePrinters::setValues(const QVariantMap &args)
0053 {
0054     if (m_args != args) {
0055         m_args = args;
0056     }
0057 }
0058 
0059 QVariantMap PageChoosePrinters::values() const
0060 {
0061     QVariantMap ret = m_args;
0062     ret[KCUPS_MEMBER_URIS] = ui->membersLV->currentSelected(true);
0063     return ret;
0064 }
0065 
0066 bool PageChoosePrinters::canProceed() const
0067 {
0068     return ui->membersLV->selectedPrinters().count() > 0;
0069 }
0070 
0071 #include "moc_PageChoosePrinters.cpp"