File indexing completed on 2024-04-28 04:03:13

0001 /*
0002     This file is part of Knights, a chess board for KDE SC 4.
0003     SPDX-FileCopyrightText: 2009, 2010, 2011 Miha Čančula <miha@noughmad.eu>
0004 
0005     SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0006 */
0007 
0008 #include "offerwidget.h"
0009 #include "gamemanager.h"
0010 #include "ui_popup.h"
0011 
0012 #include <QAction>
0013 
0014 using namespace Knights;
0015 
0016 OfferWidget::OfferWidget(const Knights::Offer& offer, QWidget* parent, Qt::WindowFlags f): KMessageWidget(offer.text, parent) {
0017     Q_UNUSED(f)
0018     offerId = offer.id;
0019     if ( offer.action != ActionNone ) {
0020         QAction* action;
0021         action = new QAction( QIcon::fromTheme(QStringLiteral("dialog-ok")), i18n("Accept"), this );
0022         connect ( action, &QAction::triggered, this, &OfferWidget::acceptClicked );
0023         addAction(action);
0024         action = new QAction( QIcon::fromTheme(QStringLiteral("edit-delete")), i18n("Decline"), this );
0025         connect ( action, &QAction::triggered, this, &OfferWidget::declineClicked );
0026         addAction ( action );
0027     }
0028     setCloseButtonVisible(true);
0029 }
0030 
0031 OfferWidget::~OfferWidget() {
0032     delete ui;
0033 }
0034 
0035 int OfferWidget::id() const {
0036     return offerId;
0037 }
0038 
0039 void OfferWidget::acceptClicked() {
0040     Q_EMIT close(offerId, AcceptOffer);
0041     deleteLater();
0042 }
0043 
0044 void OfferWidget::declineClicked() {
0045     Q_EMIT close(offerId, DeclineOffer);
0046     deleteLater();
0047 }
0048 
0049 void OfferWidget::closeClicked() {
0050     Q_EMIT close(offerId, IgnoreOffer);
0051     deleteLater();
0052 }
0053 
0054 #include "moc_offerwidget.cpp"