File indexing completed on 2024-04-28 17:05:53

0001 /*
0002     SPDX-FileCopyrightText: 2000 Shie Erlich <krusader@users.sourceforge.net>
0003     SPDX-FileCopyrightText: 2000 Rafi Yanai <krusader@users.sourceforge.net>
0004     SPDX-FileCopyrightText: 2004-2022 Krusader Krew <https://krusader.org>
0005 
0006     SPDX-License-Identifier: GPL-2.0-or-later
0007 */
0008 #include "krmaskchoice.h"
0009 
0010 // QtCore
0011 #include <QVariant>
0012 // QtWidgets
0013 #include <QDialogButtonBox>
0014 #include <QGroupBox>
0015 #include <QHBoxLayout>
0016 #include <QLabel>
0017 #include <QLayout>
0018 #include <QLineEdit>
0019 #include <QPushButton>
0020 #include <QVBoxLayout>
0021 
0022 #include <KCompletion/KComboBox>
0023 #include <KI18n/KLocalizedString>
0024 
0025 #include "../GUI/krlistwidget.h"
0026 #include "../compat.h"
0027 
0028 /**
0029  * Constructs a KrMaskChoice which is a child of 'parent', with the
0030  * name 'name' and widget flags set to 'f'
0031  *
0032  * The dialog will by default be modeless, unless you set 'modal' to
0033  * TRUE to construct a modal dialog.
0034  */
0035 KrMaskChoice::KrMaskChoice(QWidget *parent)
0036     : QDialog(parent)
0037 {
0038     setModal(true);
0039     resize(401, 314);
0040     setWindowTitle(i18n("Choose Files"));
0041 
0042     auto *MainLayout = new QVBoxLayout(this);
0043 
0044     auto *HeaderLayout = new QHBoxLayout();
0045     MainLayout->addLayout(HeaderLayout);
0046 
0047     PixmapLabel1 = new QLabel(this);
0048     PixmapLabel1->setScaledContents(true);
0049     PixmapLabel1->setMaximumSize(QSize(31, 31));
0050     HeaderLayout->addWidget(PixmapLabel1);
0051 
0052     label = new QLabel(this);
0053     label->setText(i18n("Select the following files:"));
0054     HeaderLayout->addWidget(label);
0055 
0056     selection = new KComboBox(this);
0057     selection->setEditable(true);
0058     selection->setInsertPolicy(QComboBox::InsertAtTop);
0059     selection->setAutoCompletion(true);
0060     MainLayout->addWidget(selection);
0061 
0062     auto *GroupBox1 = new QGroupBox(this);
0063     GroupBox1->setTitle(i18n("Predefined Selections"));
0064     MainLayout->addWidget(GroupBox1);
0065 
0066     auto *gbLayout = new QHBoxLayout(GroupBox1);
0067 
0068     preSelections = new KrListWidget(GroupBox1);
0069     preSelections->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
0070     preSelections->setWhatsThis(
0071         i18n("A predefined selection is a file-mask which you often use.\nSome examples are: \"*.c, *.h\", \"*.c, *.o\", etc.\nYou can add these masks to the "
0072              "list by typing them and pressing the Add button.\nDelete removes a predefined selection and Clear removes all of them.\nNotice that the line in "
0073              "which you edit the mask has its own history, you can scroll it, if needed."));
0074     gbLayout->addWidget(preSelections);
0075 
0076     auto *vbox = new QVBoxLayout();
0077     gbLayout->addLayout(vbox);
0078 
0079     PushButton7 = new QPushButton(GroupBox1);
0080     PushButton7->setText(i18n("Add"));
0081     PushButton7->setToolTip(i18n("Adds the selection in the line-edit to the list"));
0082     vbox->addWidget(PushButton7);
0083 
0084     PushButton7_2 = new QPushButton(GroupBox1);
0085     PushButton7_2->setText(i18n("Delete"));
0086     PushButton7_2->setToolTip(i18n("Delete the marked selection from the list"));
0087     vbox->addWidget(PushButton7_2);
0088 
0089     PushButton7_3 = new QPushButton(GroupBox1);
0090     PushButton7_3->setText(i18n("Clear"));
0091     PushButton7_3->setToolTip(i18n("Clears the entire list of selections"));
0092     vbox->addWidget(PushButton7_3);
0093     vbox->addItem(new QSpacerItem(5, 5, QSizePolicy::Fixed, QSizePolicy::Expanding));
0094 
0095     QDialogButtonBox *ButtonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this);
0096     MainLayout->addWidget(ButtonBox);
0097 
0098     // signals and slots connections
0099     connect(ButtonBox, &QDialogButtonBox::rejected, this, &KrMaskChoice::reject);
0100     connect(ButtonBox, &QDialogButtonBox::accepted, this, &KrMaskChoice::accept);
0101     connect(PushButton7, &QPushButton::clicked, this, &KrMaskChoice::addSelection);
0102     connect(PushButton7_2, &QPushButton::clicked, this, &KrMaskChoice::deleteSelection);
0103     connect(PushButton7_3, &QPushButton::clicked, this, &KrMaskChoice::clearSelections);
0104     connect(selection, QOverload<const QString &>::of(&KComboBox::QCOMBOBOX_ACTIVATED), selection, &KComboBox::setEditText);
0105     connect(selection->lineEdit(), &QLineEdit::returnPressed, this, &KrMaskChoice::accept);
0106     connect(preSelections, &KrListWidget::currentItemChanged, this, &KrMaskChoice::currentItemChanged);
0107     connect(preSelections, &KrListWidget::itemActivated, this, &KrMaskChoice::acceptFromList);
0108 }
0109 
0110 /*
0111  *  Destroys the object and frees any allocated resources
0112  */
0113 KrMaskChoice::~KrMaskChoice()
0114 {
0115     // no need to delete child widgets, Qt does it all for us
0116 }
0117 
0118 void KrMaskChoice::addSelection()
0119 {
0120     qWarning("KrMaskChoice::addSelection(): Not implemented yet!");
0121 }
0122 
0123 void KrMaskChoice::clearSelections()
0124 {
0125     qWarning("KrMaskChoice::clearSelections(): Not implemented yet!");
0126 }
0127 
0128 void KrMaskChoice::deleteSelection()
0129 {
0130     qWarning("KrMaskChoice::deleteSelection(): Not implemented yet!");
0131 }
0132 
0133 void KrMaskChoice::acceptFromList(QListWidgetItem *)
0134 {
0135     qWarning("KrMaskChoice::acceptFromList(QListWidgetItem *): Not implemented yet!");
0136 }
0137 
0138 void KrMaskChoice::currentItemChanged(QListWidgetItem *)
0139 {
0140     qWarning("KrMaskChoice::currentItemChanged(QListWidgetItem *): Not implemented yet!");
0141 }