File indexing completed on 2024-05-12 07:35:30

0001 /*
0002     SPDX-FileCopyrightText: 2001 Jason Harris <kstars@30doradus.org>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include "ui_addlinkdialog.h"
0010 
0011 #include <klineedit.h>
0012 #include <KLocalizedString>
0013 
0014 #include <QDialog>
0015 #include <QVBoxLayout>
0016 
0017 class QString;
0018 
0019 class AddLinkDialogUI : public QFrame, public Ui::AddLinkDialog
0020 {
0021     Q_OBJECT
0022   public:
0023     explicit AddLinkDialogUI(QWidget *parent = nullptr);
0024 };
0025 
0026 /**
0027  * @class AddLinkDialog
0028  * AddLinkDialog is a simple dialog for adding a custom URL to a popup menu.
0029  *
0030  * @author Jason Harris
0031  * @version 1.0
0032  */
0033 class AddLinkDialog : public QDialog
0034 {
0035     Q_OBJECT
0036   public:
0037     /** Constructor */
0038     explicit AddLinkDialog(QWidget *parent = nullptr, const QString &oname = i18n("object"));
0039 
0040     /** Destructor */
0041     ~AddLinkDialog() override = default;
0042 
0043     /** @return QString of the entered URL */
0044     QString url() const { return ald->URLBox->text(); }
0045 
0046     /**
0047      * @short Set the URL text
0048      * @param s the new URL text
0049      */
0050     void setURL(const QString &s) { ald->URLBox->setText(s); }
0051 
0052     /** @return QString of the entered menu entry text */
0053     QString desc() const { return ald->DescBox->text(); }
0054 
0055     /**
0056      * @short Set the Description text
0057      * @param s the new description text
0058      */
0059     void setDesc(const QString &s) { ald->DescBox->setText(s); }
0060 
0061     /** @return true if user declared the link is an image */
0062     bool isImageLink() const { return ald->ImageRadio->isChecked(); }
0063 
0064     /**
0065      * @short Set the link type
0066      * @param b if true, link is an image link.
0067      */
0068     void setImageLink(bool b) { ald->ImageRadio->setChecked(b); }
0069 
0070   private slots:
0071     /** Open the entered URL in the web browser */
0072     void checkURL(void);
0073 
0074     /**
0075      * We provide a default menu text string; this function changes the
0076      * default string if the link type (image/webpage) is changed.  Note
0077      * that if the user has changed the menu text, this function does nothing.
0078      * @param imageEnabled if true, show image string; otherwise show webpage string.
0079      */
0080     void changeDefaultDescription(bool imageEnabled);
0081 
0082   private:
0083     QString ObjectName;
0084     AddLinkDialogUI *ald;
0085 };