diff --git a/mainwindow.cpp b/mainwindow.cpp index 579bbd3..4aa4ec4 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -21,6 +21,14 @@ MainWindow::MainWindow(QWidget *parent) : qRegisterMetaType>("ViewEventSharedPtr"); connect(this, SIGNAL(showErrorAndQuit(QString)), this, SLOT(onShowErrorAndQuit(QString))); + + //加载配置 + auto settingFilePath = QDir::home().filePath(".feiq_setting.ini"); + mSettings = new Settings(settingFilePath, QSettings::IniFormat); + mSettings->setIniCodec(QTextCodec::codecForName("UTF-8")); + mTitle = mSettings->value("app/title", "mac飞秋").toString(); + setWindowTitle(mTitle); + //初始化搜索对话框 mSearchFellowDlg = new SearchFellowDlg(this); connect(mSearchFellowDlg, SIGNAL(onFellowSelected(const Fellow*)), @@ -48,6 +56,16 @@ MainWindow::MainWindow(QWidget *parent) : //初始化发送文本框 mSendTextEdit = ui->sendEdit; connect(mSendTextEdit, SIGNAL(acceptDropFiles(QList)), this, SLOT(sendFiles(QList))); + if (mSettings->value("app/send_by_enter", true).toBool()) + { + connect(mSendTextEdit, SIGNAL(enterPressed()), this, SLOT(sendText())); + connect(mSendTextEdit, SIGNAL(ctrlEnterPressed()), mSendTextEdit, SLOT(newLine())); + } + else + { + connect(mSendTextEdit, SIGNAL(ctrlEnterPressed()), this, SLOT(sendText())); + connect(mSendTextEdit, SIGNAL(enterPressed()), mSendTextEdit, SLOT(newLine())); + } //初始化Emoji对话框 mChooseEmojiDlg = new ChooseEmojiDlg(this); @@ -62,13 +80,6 @@ MainWindow::MainWindow(QWidget *parent) : connect(ui->actionSendKnock, SIGNAL(triggered(bool)), this, SLOT(sendKnock())); connect(ui->actionSendFile, SIGNAL(triggered(bool)), this, SLOT(sendFile())); - //加载配置 - auto settingFilePath = QDir::home().filePath(".feiq_setting.ini"); - mSettings = new Settings(settingFilePath, QSettings::IniFormat); - mSettings->setIniCodec(QTextCodec::codecForName("UTF-8")); - mTitle = mSettings->value("app/title", "mac飞秋").toString(); - setWindowTitle(mTitle); - //初始化飞秋引擎 connect(this, SIGNAL(feiqViewEvent(shared_ptr)), this, SLOT(handleFeiqViewEvent(shared_ptr))); diff --git a/mainwindow.ui b/mainwindow.ui index 6ba80f6..ccd54aa 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -146,9 +146,6 @@ 查找 - - Ctrl+S - @@ -168,7 +165,7 @@ 发送文本消息 - Ctrl+Return + diff --git a/plugin/rankuser.cpp b/plugin/rankuser.cpp index e0715c7..d22d09c 100644 --- a/plugin/rankuser.cpp +++ b/plugin/rankuser.cpp @@ -43,5 +43,5 @@ QString RankUser::fellowKey(const Fellow &f) int RankUser::weightOfFellow(const Fellow &f) { - return mFeiq->settings()->value(fellowKey(f), "0").toInt(); + return mFeiq->settings()->value(fellowKey(f), "0", false).toInt(); } diff --git a/readme.md b/readme.md index fa53521..9c2dfa9 100644 --- a/readme.md +++ b/readme.md @@ -26,6 +26,7 @@ host = Niubility Macbook ;设置主机名 [app] title = Feiq by CompileLife ;设置一个高端大气上档次的窗口标题名称,亮瞎围观你飞秋的人 +send_by_enter=0 ;0:cmd/ctrl+enter发送;enter回车; 1:相反 [network] custom_group=192.168.74.|192.168.82. ;设置一些广播包无法触及的子网,点号结束一个网段的定义,竖线分隔各个网段 diff --git a/sendtextedit.cpp b/sendtextedit.cpp index 68ba3b9..125cda7 100644 --- a/sendtextedit.cpp +++ b/sendtextedit.cpp @@ -3,11 +3,18 @@ #include #include #include +#include SendTextEdit::SendTextEdit(QWidget *parent) :QTextEdit(parent) { setAcceptDrops(true); + installEventFilter(this); +} + +void SendTextEdit::newLine() +{ + append(""); } void SendTextEdit::dragEnterEvent(QDragEnterEvent *e) @@ -48,3 +55,24 @@ void SendTextEdit::dropEvent(QDropEvent *e) QTextEdit::dropEvent(e); } } + +bool SendTextEdit::eventFilter(QObject *, QEvent * e) +{ + if (e->type() == QEvent::KeyPress) + { + auto keyEvent = static_cast(e); + auto enter = keyEvent->key() == Qt::Key_Return; + auto ctrl = keyEvent->modifiers() == Qt::ControlModifier; + if (enter && ctrl) + { + emit ctrlEnterPressed(); + return true; + } + else if (enter) + { + emit enterPressed(); + return true; + } + } + return false; +} diff --git a/sendtextedit.h b/sendtextedit.h index 1b02349..5e7d2be 100644 --- a/sendtextedit.h +++ b/sendtextedit.h @@ -13,10 +13,19 @@ public: signals: void acceptDropFiles(QList); + void ctrlEnterPressed(); + void enterPressed(); + +public slots: + void newLine(); protected: virtual void dragEnterEvent(QDragEnterEvent *e) override; virtual void dropEvent(QDropEvent *e) override; + virtual bool eventFilter(QObject *, QEvent *e) override; + +private: + bool mCtrlDown =false; }; #endif // SENDTEXTEDIT_H diff --git a/settings.cpp b/settings.cpp index 64d53eb..8bff7d9 100644 --- a/settings.cpp +++ b/settings.cpp @@ -6,10 +6,10 @@ Settings::Settings(const QString &fileName, QSettings::Format format, QObject *p } -QVariant Settings::value(const QString &key, const QVariant &defaultValue) +QVariant Settings::value(const QString &key, const QVariant &defaultValue, bool cacheDefault) { //如果配置中没有该项,则以默认值创建,方便用户知道有那些配置项可用 - if (!contains(key)) + if (!contains(key) && cacheDefault) { if (!defaultValue.isValid() || defaultValue.isNull()) setValue(key, "");//防止非法值 diff --git a/settings.h b/settings.h index 4af4c46..97af0f8 100644 --- a/settings.h +++ b/settings.h @@ -10,7 +10,7 @@ public: Settings(const QString &fileName, Format format, QObject *parent = Q_NULLPTR); public: //QSettings::value不是虚函数,这里并非多态重载,使用时需注意以Settings指针调用,而非QSettings调用 - QVariant value(const QString &key, const QVariant &defaultValue = QVariant()); + QVariant value(const QString &key, const QVariant &defaultValue = QVariant(), bool cacheDefault=true); };