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

58 lines
1.8 KiB
C++
Raw Normal View History

2018-06-26 14:09:39 +02:00
#include "CommandPage.hpp"
2018-01-12 23:09:05 +01:00
#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>
2018-06-26 14:09:39 +02:00
#include "Application.hpp"
#include "controllers/commands/CommandController.hpp"
#include "controllers/commands/CommandModel.hpp"
#include "util/LayoutCreator.hpp"
#include "util/StandardItemHelper.hpp"
#include "widgets/helper/EditableModelView.hpp"
//#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 {
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-06-26 17:06:17 +02:00
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-26 17:06:17 +02:00
EditableModelView *view =
layout.emplace<EditableModelView>(app->commands->createModel(nullptr)).getElement();
view->setTitles({"Trigger", "Command"});
view->getTableView()->horizontalHeader()->setStretchLastSection(true);
view->addButtonPressed.connect([] {
2018-06-26 17:20:03 +02:00
getApp()->commands->items.appendItem(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
QLabel *text = layout.emplace<QLabel>(TEXT).getElement();
2018-04-27 01:11:09 +02:00
text->setWordWrap(true);
text->setStyleSheet("color: #bbb");
2018-01-12 23:09:05 +01:00
// ---- end of layout
this->commandsEditTimer.setSingleShot(true);
}
} // namespace chatterino