mirror of
https://github.com/UltimMC/Launcher.git
synced 2025-12-14 04:32:14 +00:00
Compare commits
3 Commits
feature/re
...
feature/mo
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f04502cd82 | ||
|
|
4233e0c014 | ||
|
|
cec5f7332e |
@@ -175,11 +175,6 @@ QString BaseInstance::instanceRoot() const
|
||||
return m_rootDir;
|
||||
}
|
||||
|
||||
void BaseInstance::setInstanceRoot(QString newRoot)
|
||||
{
|
||||
m_rootDir = std::move(newRoot);
|
||||
}
|
||||
|
||||
SettingsObjectPtr BaseInstance::settings() const
|
||||
{
|
||||
return m_settings;
|
||||
@@ -230,23 +225,11 @@ QString BaseInstance::iconKey() const
|
||||
return m_settings->get("iconKey").toString();
|
||||
}
|
||||
|
||||
void BaseInstance::setName(QString val, bool requestDirChange)
|
||||
void BaseInstance::setName(QString val)
|
||||
{
|
||||
if(m_settings->get("name") == val)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//FIXME: if no change, do not set. setting involves saving a file.
|
||||
m_settings->set("name", val);
|
||||
emit propertiesChanged(this);
|
||||
if(requestDirChange && !isRunning())
|
||||
{
|
||||
emit instanceDirChangeRequest(this);
|
||||
}
|
||||
else if(requestDirChange && isRunning())
|
||||
{
|
||||
qWarning() << "Tried to rename running instance with folder";
|
||||
}
|
||||
}
|
||||
|
||||
QString BaseInstance::name() const
|
||||
|
||||
@@ -93,8 +93,6 @@ public:
|
||||
/// Path to the instance's root directory.
|
||||
QString instanceRoot() const;
|
||||
|
||||
void setInstanceRoot(QString newRoot);
|
||||
|
||||
/// Path to the instance's game root directory.
|
||||
virtual QString gameRoot() const
|
||||
{
|
||||
@@ -102,7 +100,7 @@ public:
|
||||
}
|
||||
|
||||
QString name() const;
|
||||
void setName(QString val, bool requestDirChange);
|
||||
void setName(QString val);
|
||||
|
||||
/// Value used for instance window titles
|
||||
QString windowTitle() const;
|
||||
@@ -247,8 +245,6 @@ signals:
|
||||
|
||||
void statusChanged(Status from, Status to);
|
||||
|
||||
void instanceDirChangeRequest(BaseInstance *inst);
|
||||
|
||||
protected slots:
|
||||
void iconUpdated(QString key);
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ void InstanceCopyTask::copyFinished()
|
||||
instanceSettings->registerSetting("InstanceType", "Legacy");
|
||||
|
||||
InstancePtr inst(new NullInstance(m_globalSettings, instanceSettings, m_stagingPath));
|
||||
inst->setName(m_instName, false);
|
||||
inst->setName(m_instName);
|
||||
inst->setIconKey(m_instIcon);
|
||||
emitSucceeded();
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ void InstanceCreationTask::executeTask()
|
||||
auto components = inst.getComponentList();
|
||||
components->buildingFromScratch();
|
||||
components->setComponentVersion("net.minecraft", m_version->descriptor(), true);
|
||||
inst.setName(m_instName, false);
|
||||
inst.setName(m_instName);
|
||||
inst.setIconKey(m_instIcon);
|
||||
instanceSettings->resumeSave();
|
||||
}
|
||||
|
||||
@@ -293,7 +293,7 @@ void InstanceImportTask::processFlame()
|
||||
// nuke the original files
|
||||
FS::deletePath(jarmodsPath);
|
||||
}
|
||||
instance.setName(m_instName, false);
|
||||
instance.setName(m_instName);
|
||||
m_modIdResolver.reset(new Flame::FileResolvingTask(pack));
|
||||
connect(m_modIdResolver.get(), &Flame::FileResolvingTask::succeeded, [&]()
|
||||
{
|
||||
@@ -384,7 +384,7 @@ void InstanceImportTask::processMultiMC()
|
||||
instance.resetTimePlayed();
|
||||
|
||||
// set a new nice name
|
||||
instance.setName(m_instName, false);
|
||||
instance.setName(m_instName);
|
||||
|
||||
// if the icon was specified by user, use that. otherwise pull icon from the pack
|
||||
if (m_instIcon != "default")
|
||||
|
||||
@@ -135,7 +135,7 @@ bool InstanceList::setData(const QModelIndex& index, const QVariant& value, int
|
||||
{
|
||||
return true;
|
||||
}
|
||||
pdata->setName(newName, true);
|
||||
pdata->setName(newName);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -396,7 +396,6 @@ void InstanceList::add(const QList<InstancePtr> &t)
|
||||
for(auto & ptr : t)
|
||||
{
|
||||
connect(ptr.get(), &BaseInstance::propertiesChanged, this, &InstanceList::propertiesChanged);
|
||||
connect(ptr.get(), &BaseInstance::instanceDirChangeRequest, this, &InstanceList::instanceDirUpdateRequested);
|
||||
}
|
||||
endInsertRows();
|
||||
}
|
||||
@@ -470,27 +469,6 @@ void InstanceList::propertiesChanged(BaseInstance *inst)
|
||||
}
|
||||
}
|
||||
|
||||
void InstanceList::instanceDirUpdateRequested(BaseInstance *inst)
|
||||
{
|
||||
if(m_groupMap.remove(inst->id()))
|
||||
{
|
||||
saveGroupList();
|
||||
}
|
||||
|
||||
QString oldRoot = inst->instanceRoot();
|
||||
QString instID = FS::DirNameFromString(inst->name(), m_instDir);
|
||||
|
||||
QString destination = FS::PathCombine(m_instDir, instID);
|
||||
if(!QDir().rename(oldRoot, destination))
|
||||
{
|
||||
qWarning() << "Failed to move" << inst->instanceRoot() << "to" << destination;
|
||||
}
|
||||
|
||||
FS::deletePath(oldRoot);
|
||||
|
||||
loadList();
|
||||
}
|
||||
|
||||
InstancePtr InstanceList::loadInstance(const InstanceId& id)
|
||||
{
|
||||
if(!m_groupsLoaded)
|
||||
|
||||
@@ -136,7 +136,6 @@ public slots:
|
||||
|
||||
private slots:
|
||||
void propertiesChanged(BaseInstance *inst);
|
||||
void instanceDirUpdateRequested(BaseInstance *inst);
|
||||
void providerUpdated();
|
||||
void instanceDirContentsChanged(const QString &path);
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include <QString>
|
||||
#include <QFileSystemWatcher>
|
||||
#include <QDebug>
|
||||
#include <QtCore/QDataStream>
|
||||
|
||||
SimpleModList::SimpleModList(const QString &dir) : QAbstractListModel(), m_dir(dir)
|
||||
{
|
||||
@@ -97,7 +98,7 @@ bool SimpleModList::isValid()
|
||||
}
|
||||
|
||||
// FIXME: this does not take disabled mod (with extra .disable extension) into account...
|
||||
bool SimpleModList::installMod(const QString &filename)
|
||||
bool SimpleModList::installMod(const QString &filename, bool move)
|
||||
{
|
||||
// NOTE: fix for GH-1178: remove trailing slash to avoid issues with using the empty result of QFileInfo::fileName
|
||||
auto originalPath = FS::NormalizePath(filename);
|
||||
@@ -143,7 +144,7 @@ bool SimpleModList::installMod(const QString &filename)
|
||||
}
|
||||
qDebug() << newpath << "has been deleted.";
|
||||
}
|
||||
if (!QFile::copy(fileinfo.filePath(), newpath))
|
||||
if (move ? !QFile::rename(fileinfo.filePath(), newpath) : !QFile::copy(fileinfo.filePath(), newpath))
|
||||
{
|
||||
qWarning() << "Copy from" << originalPath << "to" << newpath << "has failed.";
|
||||
// FIXME: report error in a user-visible way
|
||||
@@ -163,7 +164,7 @@ bool SimpleModList::installMod(const QString &filename)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!FS::copy(from, newpath)())
|
||||
if (move ? !QDir().rename(from, newpath) : !FS::copy(from, newpath)())
|
||||
{
|
||||
qWarning() << "Copy of folder from" << originalPath << "to" << newpath << "has (potentially partially) failed.";
|
||||
return false;
|
||||
@@ -307,15 +308,13 @@ QVariant SimpleModList::headerData(int section, Qt::Orientation orientation, int
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
Qt::ItemFlags SimpleModList::flags(const QModelIndex &index) const
|
||||
{
|
||||
Qt::ItemFlags defaultFlags = QAbstractListModel::flags(index);
|
||||
if (index.isValid())
|
||||
return Qt::ItemIsUserCheckable | Qt::ItemIsDropEnabled |
|
||||
defaultFlags;
|
||||
return Qt::ItemIsUserCheckable | Qt::ItemIsDropEnabled | Qt::ItemIsDragEnabled | defaultFlags;
|
||||
else
|
||||
return Qt::ItemIsDropEnabled | defaultFlags;
|
||||
}
|
||||
@@ -326,6 +325,11 @@ Qt::DropActions SimpleModList::supportedDropActions() const
|
||||
return Qt::CopyAction | Qt::MoveAction;
|
||||
}
|
||||
|
||||
Qt::DropActions SimpleModList::supportedDragActions() const
|
||||
{
|
||||
return Qt::CopyAction | Qt::MoveAction;
|
||||
}
|
||||
|
||||
QStringList SimpleModList::mimeTypes() const
|
||||
{
|
||||
QStringList types;
|
||||
@@ -333,6 +337,7 @@ QStringList SimpleModList::mimeTypes() const
|
||||
return types;
|
||||
}
|
||||
|
||||
|
||||
bool SimpleModList::dropMimeData(const QMimeData* data, Qt::DropAction action, int, int, const QModelIndex&)
|
||||
{
|
||||
if (action == Qt::IgnoreAction)
|
||||
@@ -357,11 +362,29 @@ bool SimpleModList::dropMimeData(const QMimeData* data, Qt::DropAction action, i
|
||||
{
|
||||
continue;
|
||||
}
|
||||
// TODO: implement not only copy, but also move
|
||||
// FIXME: handle errors here
|
||||
installMod(url.toLocalFile());
|
||||
installMod(url.toLocalFile(), action == Qt::DropAction::MoveAction);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
QMimeData *SimpleModList::mimeData(const QModelIndexList &indexes) const
|
||||
{
|
||||
auto *mimeData = new QMimeData();
|
||||
QByteArray encodedData;
|
||||
|
||||
QDataStream stream(&encodedData, QIODevice::WriteOnly);
|
||||
for(const auto &index : indexes)
|
||||
{
|
||||
if(index.isValid())
|
||||
{
|
||||
auto mod = mods[index.row()];
|
||||
stream << "file://" << mod.filename().absoluteFilePath() << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
mimeData->setData("text/uri-list", encodedData);
|
||||
return mimeData;
|
||||
}
|
||||
@@ -49,11 +49,13 @@ public:
|
||||
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||
virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
|
||||
Qt::DropActions supportedDropActions() const override;
|
||||
Qt::DropActions supportedDragActions() const override;
|
||||
|
||||
/// flags, mostly to support drag&drop
|
||||
virtual Qt::ItemFlags flags(const QModelIndex &index) const override;
|
||||
QStringList mimeTypes() const override;
|
||||
bool dropMimeData(const QMimeData * data, Qt::DropAction action, int row, int column, const QModelIndex & parent) override;
|
||||
QMimeData *mimeData(const QModelIndexList &indexes) const override;
|
||||
|
||||
virtual int rowCount(const QModelIndex &) const override
|
||||
{
|
||||
@@ -83,7 +85,7 @@ public:
|
||||
/**
|
||||
* Adds the given mod to the list at the given index - if the list supports custom ordering
|
||||
*/
|
||||
bool installMod(const QString& filename);
|
||||
bool installMod(const QString& filename, bool move);
|
||||
|
||||
/// Deletes all the selected mods
|
||||
virtual bool deleteMods(const QModelIndexList &indexes);
|
||||
|
||||
@@ -33,7 +33,7 @@ slots:
|
||||
QString folder = source;
|
||||
QTemporaryDir tempDir;
|
||||
SimpleModList m(tempDir.path());
|
||||
m.installMod(folder);
|
||||
m.installMod(folder, false);
|
||||
verify(tempDir.path());
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ slots:
|
||||
QString folder = source + '/';
|
||||
QTemporaryDir tempDir;
|
||||
SimpleModList m(tempDir.path());
|
||||
m.installMod(folder);
|
||||
m.installMod(folder, false);
|
||||
verify(tempDir.path());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ void LegacyUpgradeTask::copyFinished()
|
||||
// NOTE: this scope ensures the instance is fully saved before we emitSucceeded
|
||||
{
|
||||
MinecraftInstance inst(m_globalSettings, instanceSettings, m_stagingPath);
|
||||
inst.setName(m_instName, false);
|
||||
inst.setName(m_instName);
|
||||
|
||||
QString preferredVersionNumber = decideVersion(legacyInst->currentVersionId(), legacyInst->intendedVersionId());
|
||||
if(preferredVersionNumber.isNull())
|
||||
|
||||
@@ -186,7 +186,7 @@ void FtbPackInstallTask::install()
|
||||
|
||||
progress(4, 4);
|
||||
|
||||
instance.setName(m_instName, false);
|
||||
instance.setName(m_instName);
|
||||
if(m_instIcon == "default")
|
||||
{
|
||||
m_instIcon = "ftb_logo";
|
||||
|
||||
@@ -145,8 +145,6 @@ SET(MULTIMC_SOURCES
|
||||
# GUI - dialogs
|
||||
dialogs/AboutDialog.cpp
|
||||
dialogs/AboutDialog.h
|
||||
dialogs/CheckableInputDialog.cpp
|
||||
dialogs/CheckableInputDialog.h
|
||||
dialogs/ProfileSelectDialog.cpp
|
||||
dialogs/ProfileSelectDialog.h
|
||||
dialogs/CopyInstanceDialog.cpp
|
||||
@@ -260,7 +258,6 @@ SET(MULTIMC_UIS
|
||||
pages/modplatform/ImportPage.ui
|
||||
|
||||
# Dialogs
|
||||
dialogs/CheckableInputDialog.ui
|
||||
dialogs/CopyInstanceDialog.ui
|
||||
dialogs/NewComponentDialog.ui
|
||||
dialogs/NewInstanceDialog.ui
|
||||
|
||||
@@ -31,7 +31,6 @@
|
||||
#include <QtWidgets/QAction>
|
||||
#include <QtWidgets/QApplication>
|
||||
#include <QtWidgets/QButtonGroup>
|
||||
#include <QtWidgets/QCheckBox>
|
||||
#include <QtWidgets/QHBoxLayout>
|
||||
#include <QtWidgets/QHeaderView>
|
||||
#include <QtWidgets/QMainWindow>
|
||||
@@ -75,7 +74,6 @@
|
||||
#include "groupview/InstanceDelegate.h"
|
||||
#include "widgets/LabeledToolButton.h"
|
||||
#include "widgets/ServerStatus.h"
|
||||
#include "dialogs/CheckableInputDialog.h"
|
||||
#include "dialogs/NewInstanceDialog.h"
|
||||
#include "dialogs/ProgressDialog.h"
|
||||
#include "dialogs/AboutDialog.h"
|
||||
@@ -847,7 +845,7 @@ void MainWindow::showInstanceContextMenu(const QPoint &pos)
|
||||
actionSep->setSeparator(true);
|
||||
|
||||
bool onInstance = view->indexAt(pos).isValid();
|
||||
if (onInstance && m_selectedInstance)
|
||||
if (onInstance)
|
||||
{
|
||||
actions = ui->instanceToolBar->actions();
|
||||
|
||||
@@ -1366,7 +1364,6 @@ void MainWindow::finalizeInstance(InstancePtr inst)
|
||||
});
|
||||
if(update)
|
||||
{
|
||||
loadDialog.setSkipButton(true, tr("Abort"));
|
||||
loadDialog.setSkipButton(true, tr("Abort"));
|
||||
loadDialog.execWithTask(update.get());
|
||||
}
|
||||
@@ -1694,15 +1691,7 @@ void MainWindow::on_actionRenameInstance_triggered()
|
||||
{
|
||||
if (m_selectedInstance)
|
||||
{
|
||||
CheckableInputDialog dialog(this);
|
||||
dialog.setWindowTitle(tr("Rename"));
|
||||
dialog.setText(tr("Enter new name for the instance:"));
|
||||
dialog.setCheckboxText(tr("Rename instance folder"));
|
||||
dialog.setExtraText(tr("WARNING: Renaming the instance folder may break shortcuts and automation you made!"));
|
||||
if(dialog.exec() == QDialog::Accepted && !dialog.getInput().isEmpty())
|
||||
{
|
||||
m_selectedInstance->setName(dialog.getInput(), dialog.checkboxChecked());
|
||||
}
|
||||
view->edit(view->currentIndex());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1831,7 +1820,6 @@ void MainWindow::instanceChanged(const QModelIndex ¤t, const QModelIndex &
|
||||
ui->actionLaunchInstanceOffline->setEnabled(m_selectedInstance->canLaunch());
|
||||
ui->actionExportInstance->setEnabled(m_selectedInstance->canExport());
|
||||
ui->renameButton->setText(m_selectedInstance->name());
|
||||
ui->actionRenameInstance->setDisabled(m_selectedInstance->isRunning());
|
||||
m_statusLeft->setText(m_selectedInstance->getStatusbarDescription());
|
||||
updateInstanceToolIcon(m_selectedInstance->iconKey());
|
||||
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
#include "CheckableInputDialog.h"
|
||||
|
||||
#include <QPushButton>
|
||||
#include <QDebug>
|
||||
|
||||
#include "ui_CheckableInputDialog.h"
|
||||
|
||||
CheckableInputDialog::CheckableInputDialog(QWidget *parent) : QDialog(parent), ui(new Ui::CheckableInputDialog)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
connect(ui->buttonBox->button(QDialogButtonBox::StandardButton::Ok), &QPushButton::clicked, this, &QDialog::accept);
|
||||
connect(ui->buttonBox->button(QDialogButtonBox::StandardButton::Cancel), &QPushButton::clicked, this,
|
||||
&QDialog::reject);
|
||||
}
|
||||
|
||||
CheckableInputDialog::~CheckableInputDialog()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void CheckableInputDialog::setText(QString text)
|
||||
{
|
||||
ui->label->setText(text);
|
||||
}
|
||||
|
||||
void CheckableInputDialog::setExtraText(QString text)
|
||||
{
|
||||
ui->extraText->setText(text);
|
||||
}
|
||||
|
||||
|
||||
void CheckableInputDialog::setCheckboxText(QString checkboxText)
|
||||
{
|
||||
ui->checkBox->setText(checkboxText);
|
||||
}
|
||||
|
||||
bool CheckableInputDialog::checkboxChecked()
|
||||
{
|
||||
return ui->checkBox->checkState();
|
||||
}
|
||||
|
||||
QString CheckableInputDialog::getInput()
|
||||
{
|
||||
return ui->lineEdit->text();
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
class CheckableInputDialog;
|
||||
}
|
||||
|
||||
class CheckableInputDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
CheckableInputDialog(QWidget *parent);
|
||||
~CheckableInputDialog();
|
||||
|
||||
void setText(QString text);
|
||||
void setExtraText(QString text);
|
||||
void setCheckboxText(QString checkboxText);
|
||||
|
||||
bool checkboxChecked();
|
||||
QString getInput();
|
||||
|
||||
private:
|
||||
Ui::CheckableInputDialog *ui;
|
||||
|
||||
};
|
||||
@@ -1,94 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>CheckableInputDialog</class>
|
||||
<widget class="QDialog" name="CheckableInputDialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>186</width>
|
||||
<height>112</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Dialog</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>TextLabel</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="checkBox">
|
||||
<property name="text">
|
||||
<string>CheckBox</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="extraText">
|
||||
<property name="text">
|
||||
<string>TextLabel</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>CheckableInputDialog</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>248</x>
|
||||
<y>254</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>CheckableInputDialog</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>316</x>
|
||||
<y>260</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
||||
@@ -341,4 +341,82 @@ QSize ListViewDelegate::sizeHint(const QStyleOptionViewItem &option,
|
||||
return sz;
|
||||
}
|
||||
|
||||
class NoReturnTextEdit: public QTextEdit
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit NoReturnTextEdit(QWidget *parent) : QTextEdit(parent)
|
||||
{
|
||||
setTextInteractionFlags(Qt::TextEditorInteraction);
|
||||
setHorizontalScrollBarPolicy(Qt::ScrollBarPolicy::ScrollBarAlwaysOff);
|
||||
setVerticalScrollBarPolicy(Qt::ScrollBarPolicy::ScrollBarAlwaysOff);
|
||||
}
|
||||
bool event(QEvent * event) override
|
||||
{
|
||||
auto eventType = event->type();
|
||||
if(eventType == QEvent::KeyPress || eventType == QEvent::KeyRelease)
|
||||
{
|
||||
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
|
||||
auto key = keyEvent->key();
|
||||
if (key == Qt::Key_Return || key == Qt::Key_Enter)
|
||||
{
|
||||
emit editingDone();
|
||||
return true;
|
||||
}
|
||||
if(key == Qt::Key_Tab)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return QTextEdit::event(event);
|
||||
}
|
||||
signals:
|
||||
void editingDone();
|
||||
};
|
||||
|
||||
void ListViewDelegate::updateEditorGeometry(QWidget* editor, const QStyleOptionViewItem& option, const QModelIndex& index) const
|
||||
{
|
||||
const int iconSize = 48;
|
||||
QRect textRect = option.rect;
|
||||
// QStyle *style = option.widget ? option.widget->style() : QApplication::style();
|
||||
textRect.adjust(0, iconSize + 5, 0, 0);
|
||||
editor->setGeometry(textRect);
|
||||
}
|
||||
|
||||
void ListViewDelegate::setEditorData(QWidget* editor, const QModelIndex& index) const
|
||||
{
|
||||
auto text = index.data(Qt::EditRole).toString();
|
||||
QTextEdit * realeditor = qobject_cast<NoReturnTextEdit *>(editor);
|
||||
realeditor->setAlignment(Qt::AlignHCenter | Qt::AlignTop);
|
||||
realeditor->append(text);
|
||||
realeditor->selectAll();
|
||||
realeditor->document()->clearUndoRedoStacks();
|
||||
}
|
||||
|
||||
void ListViewDelegate::setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const
|
||||
{
|
||||
QTextEdit * realeditor = qobject_cast<NoReturnTextEdit *>(editor);
|
||||
QString text = realeditor->toPlainText();
|
||||
text.replace(QChar('\n'), QChar(' '));
|
||||
text = text.trimmed();
|
||||
if(text.size() != 0)
|
||||
{
|
||||
model->setData(index, text);
|
||||
}
|
||||
}
|
||||
|
||||
QWidget * ListViewDelegate::createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const
|
||||
{
|
||||
auto editor = new NoReturnTextEdit(parent);
|
||||
connect(editor, &NoReturnTextEdit::editingDone, this, &ListViewDelegate::editingDone);
|
||||
return editor;
|
||||
}
|
||||
|
||||
void ListViewDelegate::editingDone()
|
||||
{
|
||||
NoReturnTextEdit *editor = qobject_cast<NoReturnTextEdit *>(sender());
|
||||
emit commitData(editor);
|
||||
emit closeEditor(editor);
|
||||
}
|
||||
|
||||
#include "InstanceDelegate.moc"
|
||||
|
||||
@@ -28,4 +28,12 @@ public:
|
||||
|
||||
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
|
||||
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override;
|
||||
void updateEditorGeometry(QWidget * editor, const QStyleOptionViewItem & option, const QModelIndex & index) const override;
|
||||
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;
|
||||
|
||||
private slots:
|
||||
void editingDone();
|
||||
};
|
||||
|
||||
@@ -163,7 +163,7 @@ void ModFolderPage::on_addModBtn_clicked()
|
||||
{
|
||||
for (auto filename : list)
|
||||
{
|
||||
m_mods->installMod(filename);
|
||||
m_mods->installMod(filename, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,8 +35,10 @@ ModListView::ModListView ( QWidget* parent )
|
||||
setHorizontalScrollBarPolicy ( Qt::ScrollBarAsNeeded );
|
||||
setDropIndicatorShown(true);
|
||||
setDragEnabled(true);
|
||||
setDragDropMode(QAbstractItemView::DropOnly);
|
||||
setDragDropMode(QAbstractItemView::DragDrop);
|
||||
viewport()->setAcceptDrops(true);
|
||||
setAcceptDrops(true);
|
||||
setDefaultDropAction(Qt::CopyAction);
|
||||
}
|
||||
|
||||
void ModListView::setModel ( QAbstractItemModel* model )
|
||||
@@ -64,3 +66,18 @@ void ModListView::setModel ( QAbstractItemModel* model )
|
||||
head->setSectionResizeMode(i, QHeaderView::ResizeToContents);
|
||||
}
|
||||
}
|
||||
|
||||
void ModListView::dragEnterEvent(QDragEnterEvent *event)
|
||||
{
|
||||
event->accept();
|
||||
}
|
||||
|
||||
void ModListView::dragMoveEvent(QDragMoveEvent *event)
|
||||
{
|
||||
event->accept();
|
||||
}
|
||||
|
||||
void ModListView::dropEvent(QDropEvent *event)
|
||||
{
|
||||
QAbstractItemView::dropEvent(event);
|
||||
}
|
||||
|
||||
@@ -22,6 +22,10 @@ class ModListView: public QTreeView
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ModListView ( QWidget* parent = 0 );
|
||||
virtual void setModel ( QAbstractItemModel* model );
|
||||
explicit ModListView ( QWidget* parent = nullptr );
|
||||
void setModel ( QAbstractItemModel* model ) override;
|
||||
|
||||
void dragEnterEvent(QDragEnterEvent *event) override;
|
||||
void dragMoveEvent(QDragMoveEvent *event) override;
|
||||
void dropEvent(QDropEvent *event) override;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user