@@ -21,6 +21,14 @@ MainWindow::MainWindow(QWidget *parent) : | |||||
qRegisterMetaType<shared_ptr<ViewEvent>>("ViewEventSharedPtr"); | qRegisterMetaType<shared_ptr<ViewEvent>>("ViewEventSharedPtr"); | ||||
connect(this, SIGNAL(showErrorAndQuit(QString)), this, SLOT(onShowErrorAndQuit(QString))); | 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); | mSearchFellowDlg = new SearchFellowDlg(this); | ||||
connect(mSearchFellowDlg, SIGNAL(onFellowSelected(const Fellow*)), | connect(mSearchFellowDlg, SIGNAL(onFellowSelected(const Fellow*)), | ||||
@@ -48,6 +56,16 @@ MainWindow::MainWindow(QWidget *parent) : | |||||
//初始化发送文本框 | //初始化发送文本框 | ||||
mSendTextEdit = ui->sendEdit; | mSendTextEdit = ui->sendEdit; | ||||
connect(mSendTextEdit, SIGNAL(acceptDropFiles(QList<QFileInfo>)), this, SLOT(sendFiles(QList<QFileInfo>))); | connect(mSendTextEdit, SIGNAL(acceptDropFiles(QList<QFileInfo>)), this, SLOT(sendFiles(QList<QFileInfo>))); | ||||
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对话框 | //初始化Emoji对话框 | ||||
mChooseEmojiDlg = new ChooseEmojiDlg(this); | mChooseEmojiDlg = new ChooseEmojiDlg(this); | ||||
@@ -62,13 +80,6 @@ MainWindow::MainWindow(QWidget *parent) : | |||||
connect(ui->actionSendKnock, SIGNAL(triggered(bool)), this, SLOT(sendKnock())); | connect(ui->actionSendKnock, SIGNAL(triggered(bool)), this, SLOT(sendKnock())); | ||||
connect(ui->actionSendFile, SIGNAL(triggered(bool)), this, SLOT(sendFile())); | 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<ViewEvent>)), this, SLOT(handleFeiqViewEvent(shared_ptr<ViewEvent>))); | connect(this, SIGNAL(feiqViewEvent(shared_ptr<ViewEvent>)), this, SLOT(handleFeiqViewEvent(shared_ptr<ViewEvent>))); | ||||
@@ -146,9 +146,6 @@ | |||||
<property name="text"> | <property name="text"> | ||||
<string>查找</string> | <string>查找</string> | ||||
</property> | </property> | ||||
<property name="shortcut"> | |||||
<string>Ctrl+S</string> | |||||
</property> | |||||
</action> | </action> | ||||
<action name="actionSettings"> | <action name="actionSettings"> | ||||
<property name="text"> | <property name="text"> | ||||
@@ -168,7 +165,7 @@ | |||||
<string>发送文本消息</string> | <string>发送文本消息</string> | ||||
</property> | </property> | ||||
<property name="shortcut"> | <property name="shortcut"> | ||||
<string>Ctrl+Return</string> | |||||
<string/> | |||||
</property> | </property> | ||||
</action> | </action> | ||||
<action name="actionSendKnock"> | <action name="actionSendKnock"> | ||||
@@ -43,5 +43,5 @@ QString RankUser::fellowKey(const Fellow &f) | |||||
int RankUser::weightOfFellow(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(); | |||||
} | } |
@@ -26,6 +26,7 @@ host = Niubility Macbook ;设置主机名 | |||||
[app] | [app] | ||||
title = Feiq by CompileLife ;设置一个高端大气上档次的窗口标题名称,亮瞎围观你飞秋的人 | title = Feiq by CompileLife ;设置一个高端大气上档次的窗口标题名称,亮瞎围观你飞秋的人 | ||||
send_by_enter=0 ;0:cmd/ctrl+enter发送;enter回车; 1:相反 | |||||
[network] | [network] | ||||
custom_group=192.168.74.|192.168.82. ;设置一些广播包无法触及的子网,点号结束一个网段的定义,竖线分隔各个网段 | custom_group=192.168.74.|192.168.82. ;设置一些广播包无法触及的子网,点号结束一个网段的定义,竖线分隔各个网段 | ||||
@@ -3,11 +3,18 @@ | |||||
#include <QDropEvent> | #include <QDropEvent> | ||||
#include <QMimeData> | #include <QMimeData> | ||||
#include <QFileInfo> | #include <QFileInfo> | ||||
#include <QDebug> | |||||
SendTextEdit::SendTextEdit(QWidget *parent) | SendTextEdit::SendTextEdit(QWidget *parent) | ||||
:QTextEdit(parent) | :QTextEdit(parent) | ||||
{ | { | ||||
setAcceptDrops(true); | setAcceptDrops(true); | ||||
installEventFilter(this); | |||||
} | |||||
void SendTextEdit::newLine() | |||||
{ | |||||
append(""); | |||||
} | } | ||||
void SendTextEdit::dragEnterEvent(QDragEnterEvent *e) | void SendTextEdit::dragEnterEvent(QDragEnterEvent *e) | ||||
@@ -48,3 +55,24 @@ void SendTextEdit::dropEvent(QDropEvent *e) | |||||
QTextEdit::dropEvent(e); | QTextEdit::dropEvent(e); | ||||
} | } | ||||
} | } | ||||
bool SendTextEdit::eventFilter(QObject *, QEvent * e) | |||||
{ | |||||
if (e->type() == QEvent::KeyPress) | |||||
{ | |||||
auto keyEvent = static_cast<QKeyEvent*>(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; | |||||
} |
@@ -13,10 +13,19 @@ public: | |||||
signals: | signals: | ||||
void acceptDropFiles(QList<QFileInfo>); | void acceptDropFiles(QList<QFileInfo>); | ||||
void ctrlEnterPressed(); | |||||
void enterPressed(); | |||||
public slots: | |||||
void newLine(); | |||||
protected: | protected: | ||||
virtual void dragEnterEvent(QDragEnterEvent *e) override; | virtual void dragEnterEvent(QDragEnterEvent *e) override; | ||||
virtual void dropEvent(QDropEvent *e) override; | virtual void dropEvent(QDropEvent *e) override; | ||||
virtual bool eventFilter(QObject *, QEvent *e) override; | |||||
private: | |||||
bool mCtrlDown =false; | |||||
}; | }; | ||||
#endif // SENDTEXTEDIT_H | #endif // SENDTEXTEDIT_H |
@@ -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()) | if (!defaultValue.isValid() || defaultValue.isNull()) | ||||
setValue(key, "");//防止非法值 | setValue(key, "");//防止非法值 | ||||
@@ -10,7 +10,7 @@ public: | |||||
Settings(const QString &fileName, Format format, QObject *parent = Q_NULLPTR); | Settings(const QString &fileName, Format format, QObject *parent = Q_NULLPTR); | ||||
public: | public: | ||||
//QSettings::value不是虚函数,这里并非多态重载,使用时需注意以Settings指针调用,而非QSettings调用 | //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); | |||||
}; | }; | ||||