mirror-chatterino2/src/widgets/settingspages/commandpage.cpp

68 lines
2.2 KiB
C++
Raw Normal View History

2018-01-12 23:09:05 +01:00
#include "commandpage.hpp"
#include <QHeaderView>
2018-01-12 23:09:05 +01:00
#include <QLabel>
2018-04-27 01:11:09 +02:00
#include <QPushButton>
#include <QStandardItemModel>
#include <QTableView>
2018-01-12 23:09:05 +01:00
#include <QTextEdit>
#include "application.hpp"
#include "controllers/commands/commandcontroller.hpp"
#include "controllers/commands/commandmodel.hpp"
2018-01-16 00:26:04 +01:00
#include "util/layoutcreator.hpp"
2018-04-27 01:11:09 +02:00
#include "util/standarditemhelper.hpp"
#include "widgets/helper/editablemodelview.hpp"
2018-04-27 01:11:09 +02:00
//#include "widgets/helper/comboboxitemdelegate.hpp"
2018-01-12 23:09:05 +01:00
#include <QLabel>
#include <QTextEdit>
2018-01-12 23:09:05 +01:00
// clang-format off
2018-04-27 01:11:09 +02:00
#define TEXT "{1} => first word, {2} => second word, ...\n"\
"{1+} => first word and after, {2+} => second word and after, ...\n"\
"{{1} => {1}"
2018-01-12 23:09:05 +01:00
// clang-format on
namespace chatterino {
namespace widgets {
namespace settingspages {
CommandPage::CommandPage()
2018-04-26 23:07:02 +02:00
: SettingsPage("Commands", ":/images/commands.svg")
2018-01-12 23:09:05 +01:00
{
auto app = getApp();
2018-04-27 01:11:09 +02:00
2018-01-12 23:09:05 +01:00
util::LayoutCreator<CommandPage> layoutCreator(this);
2018-01-13 00:04:47 +01:00
auto layout = layoutCreator.emplace<QVBoxLayout>().withoutMargin();
2018-01-12 23:09:05 +01:00
2018-06-21 13:02:34 +02:00
auto warning = layout.emplace<QLabel>("The command system will be reworked in the "
2018-06-21 22:02:35 +02:00
"future!\nYour saved commands will get discarded then. "
"Deleting commands crashes chatterino right now.");
2018-06-21 13:02:34 +02:00
warning.getElement()->setStyleSheet("color: #f00");
helper::EditableModelView *view =
*layout.emplace<helper::EditableModelView>(app->commands->createModel(nullptr));
view->setTitles({"Trigger", "Command"});
view->getTableView()->horizontalHeader()->setStretchLastSection(true);
view->addButtonPressed.connect([] {
getApp()->commands->items.appendItem(
controllers::commands::Command{"/command", "I made a new command HeyGuys"});
});
2018-04-27 01:11:09 +02:00
layout.append(this->createCheckBox("Also match the trigger at the end of the message",
app->settings->allowCommandsAtEnd));
2018-01-12 23:09:05 +01:00
2018-04-27 01:11:09 +02:00
QLabel *text = *layout.emplace<QLabel>(TEXT);
text->setWordWrap(true);
text->setStyleSheet("color: #bbb");
2018-01-12 23:09:05 +01:00
// ---- end of layout
this->commandsEditTimer.setSingleShot(true);
}
} // namespace settingspages
} // namespace widgets
} // namespace chatterino