#134 More work done on the new server config editing.
In-table editing and icons to better see what's a network and a server. Known issue when adding servers to networks that are expanded in the tree view, need to collapse and re-expand the network to see it. Saving to JSON and deleting servers/networks is not done yet.master
parent
c26715cf65
commit
9185893037
@ -0,0 +1,80 @@ |
||||
/*
|
||||
* IdealIRC - Internet Relay Chat client |
||||
* Copyright (C) 2022 Tom-Andre Barstad. |
||||
* This software is licensed under the Software Attribution License. |
||||
* See LICENSE for more information. |
||||
*/ |
||||
|
||||
#include "ServerOptionsDelegate.h" |
||||
#include "ServerItem.h" |
||||
#include <QInputDialog> |
||||
#include <QPushButton> |
||||
#include <QDebug> |
||||
|
||||
ServerOptionsDelegate::ServerOptionsDelegate(QObject* parent) |
||||
: QStyledItemDelegate(parent) |
||||
{} |
||||
|
||||
QWidget* ServerOptionsDelegate::createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const |
||||
{ |
||||
if (!index.isValid()) |
||||
return nullptr; |
||||
|
||||
if (index.column() == 2) { |
||||
auto* btn = new QPushButton(tr("SSL"), parent); |
||||
btn->setCheckable(true); |
||||
return btn; |
||||
} |
||||
else if (index.column() == 3) { |
||||
auto* btn = new QPushButton(tr("Password"), parent); |
||||
auto* item = static_cast<ServerItem*>(index.internalPointer()); |
||||
connect(btn, &QPushButton::pressed, |
||||
[item, parent] { |
||||
auto password = QInputDialog::getText( |
||||
parent, |
||||
tr("Enter password"), |
||||
tr("New password for %1:").arg(item->name()), |
||||
QLineEdit::Password |
||||
); |
||||
|
||||
item->setPassword(password); |
||||
}); |
||||
|
||||
return btn; |
||||
} |
||||
else { |
||||
return nullptr; |
||||
} |
||||
} |
||||
|
||||
void ServerOptionsDelegate::setEditorData(QWidget* editor, const QModelIndex& index) const |
||||
{ |
||||
const auto* item = static_cast<const ServerItem*>(index.internalPointer()); |
||||
|
||||
if (index.column() == 2) { |
||||
auto* btn = qobject_cast<QPushButton*>(editor); |
||||
if (btn) |
||||
btn->setChecked(item->ssl()); |
||||
else |
||||
qCritical() << "SSL button is not a QPushButton?!"; |
||||
} |
||||
|
||||
} |
||||
|
||||
void ServerOptionsDelegate::setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const |
||||
{ |
||||
auto* item = static_cast<ServerItem*>(index.internalPointer()); |
||||
|
||||
if (index.column() == 2) { |
||||
auto* btn = qobject_cast<QPushButton*>(editor); |
||||
if (btn) |
||||
item->setSsl(btn->isChecked()); |
||||
else |
||||
qCritical() << "SSL button is not a QPushButton?!"; |
||||
} |
||||
} |
||||
|
||||
void ServerOptionsDelegate::updateEditorGeometry(QWidget* editor, const QStyleOptionViewItem& option, const QModelIndex& /*index*/) const |
||||
{ |
||||
editor->setGeometry(option.rect); |
||||
} |
@ -0,0 +1,26 @@ |
||||
/*
|
||||
* IdealIRC - Internet Relay Chat client |
||||
* Copyright (C) 2022 Tom-Andre Barstad. |
||||
* This software is licensed under the Software Attribution License. |
||||
* See LICENSE for more information. |
||||
*/ |
||||
|
||||
#ifndef SERVEROPTIONSDELEGATE_H |
||||
#define SERVEROPTIONSDELEGATE_H |
||||
|
||||
#include <QStyledItemDelegate> |
||||
|
||||
class ServerOptionsDelegate : public QStyledItemDelegate |
||||
{ |
||||
Q_OBJECT |
||||
|
||||
public: |
||||
explicit ServerOptionsDelegate(QObject* parent = nullptr); |
||||
|
||||
QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const override; |
||||
void setEditorData(QWidget* editor, const QModelIndex& index) const override; |
||||
void setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const override; |
||||
void updateEditorGeometry(QWidget* editor, const QStyleOptionViewItem& option, const QModelIndex& index) const override; |
||||
}; |
||||
|
||||
#endif // SERVEROPTIONSDELEGATE_H
|
After Width: | Height: | Size: 3.1 KiB |
Loading…
Reference in new issue