Browse Source

feat: remove search button and add line in context menu

reviewable/pr4955/r2
TriKriSta 8 years ago
parent
commit
8bb80c770c
  1. 2
      res.qrc
  2. 29
      src/widget/chatformheader.cpp
  3. 4
      src/widget/chatformheader.h
  4. 24
      src/widget/form/chatform.cpp
  5. 2
      src/widget/form/chatform.h
  6. 18
      src/widget/form/genericchatform.cpp
  7. 2
      src/widget/form/genericchatform.h
  8. 25
      src/widget/searchform.cpp
  9. 8
      src/widget/searchform.h
  10. 12
      ui/chatForm/buttons.css
  11. 55
      ui/chatForm/hideButton.svg

2
res.qrc

@ -95,8 +95,8 @@
<file>img/caps_lock.svg</file> <file>img/caps_lock.svg</file>
<file>ui/contentDialog/contentDialog.css</file> <file>ui/contentDialog/contentDialog.css</file>
<file>ui/tooliconsZone/tooliconsZone.css</file> <file>ui/tooliconsZone/tooliconsZone.css</file>
<file>ui/chatForm/searchButton.svg</file>
<file>ui/chatForm/searchDownButton.svg</file> <file>ui/chatForm/searchDownButton.svg</file>
<file>ui/chatForm/searchUpButton.svg</file> <file>ui/chatForm/searchUpButton.svg</file>
<file>ui/chatForm/hideButton.svg</file>
</qresource> </qresource>
</RCC> </RCC>

29
src/widget/chatformheader.cpp

@ -76,12 +76,6 @@ const QString MIC_TOOL_TIP[] = {
ChatFormHeader::tr("Mute microphone"), ChatFormHeader::tr("Mute microphone"),
}; };
const QString SEARCH_TOOL_TIP[] = {
ChatFormHeader::tr("Search in text"),
ChatFormHeader::tr("Unmute search"),
ChatFormHeader::tr("Mute search"),
};
template <class T, class Fun> template <class T, class Fun>
QPushButton* createButton(const QString& name, T* self, Fun onClickSlot) QPushButton* createButton(const QString& name, T* self, Fun onClickSlot)
{ {
@ -117,7 +111,6 @@ ChatFormHeader::ChatFormHeader(QWidget* parent)
, videoState{CallButtonState::Disabled} , videoState{CallButtonState::Disabled}
, volState{ToolButtonState::Disabled} , volState{ToolButtonState::Disabled}
, micState{ToolButtonState::Disabled} , micState{ToolButtonState::Disabled}
, searchState{ToolButtonState::Off}
{ {
QHBoxLayout* headLayout = new QHBoxLayout(); QHBoxLayout* headLayout = new QHBoxLayout();
avatar = new MaskablePixmapWidget(this, AVATAR_SIZE, ":/img/avatar_mask.svg"); avatar = new MaskablePixmapWidget(this, AVATAR_SIZE, ":/img/avatar_mask.svg");
@ -139,7 +132,6 @@ ChatFormHeader::ChatFormHeader(QWidget* parent)
volButton = createButton("volButton", this, &ChatFormHeader::volMuteToggle); volButton = createButton("volButton", this, &ChatFormHeader::volMuteToggle);
callButton = createButton("callButton", this, &ChatFormHeader::callTriggered); callButton = createButton("callButton", this, &ChatFormHeader::callTriggered);
videoButton = createButton("videoButton", this, &ChatFormHeader::videoCallTriggered); videoButton = createButton("videoButton", this, &ChatFormHeader::videoCallTriggered);
searchButton = createButton("searchButton", this, &ChatFormHeader::searchTriggered);
QVBoxLayout* micButtonsLayout = new QVBoxLayout(); QVBoxLayout* micButtonsLayout = new QVBoxLayout();
micButtonsLayout->setSpacing(MIC_BUTTONS_LAYOUT_SPACING); micButtonsLayout->setSpacing(MIC_BUTTONS_LAYOUT_SPACING);
@ -147,10 +139,9 @@ ChatFormHeader::ChatFormHeader(QWidget* parent)
micButtonsLayout->addWidget(volButton, Qt::AlignTop | Qt::AlignRight); micButtonsLayout->addWidget(volButton, Qt::AlignTop | Qt::AlignRight);
QGridLayout* buttonsLayout = new QGridLayout(); QGridLayout* buttonsLayout = new QGridLayout();
buttonsLayout->addWidget(searchButton, 0, 0, 2, 1, Qt::AlignTop); buttonsLayout->addLayout(micButtonsLayout, 0, 0, 2, 1, Qt::AlignTop | Qt::AlignRight);
buttonsLayout->addLayout(micButtonsLayout, 0, 1, 2, 1, Qt::AlignTop | Qt::AlignRight); buttonsLayout->addWidget(callButton, 0, 1, 2, 1, Qt::AlignTop);
buttonsLayout->addWidget(callButton, 0, 2, 2, 1, Qt::AlignTop); buttonsLayout->addWidget(videoButton, 0, 2, 2, 1, Qt::AlignTop);
buttonsLayout->addWidget(videoButton, 0, 3, 2, 1, Qt::AlignTop);
buttonsLayout->setVerticalSpacing(0); buttonsLayout->setVerticalSpacing(0);
buttonsLayout->setHorizontalSpacing(BUTTONS_LAYOUT_HOR_SPACING); buttonsLayout->setHorizontalSpacing(BUTTONS_LAYOUT_HOR_SPACING);
@ -180,7 +171,6 @@ void ChatFormHeader::setMode(ChatFormHeader::Mode mode)
videoButton->hide(); videoButton->hide();
volButton->hide(); volButton->hide();
micButton->hide(); micButton->hide();
searchButton->hide();
} }
} }
@ -190,7 +180,6 @@ void ChatFormHeader::retranslateUi()
setStateToolTip(videoButton, videoState, VIDEO_TOOL_TIP); setStateToolTip(videoButton, videoState, VIDEO_TOOL_TIP);
setStateToolTip(micButton, micState, MIC_TOOL_TIP); setStateToolTip(micButton, micState, MIC_TOOL_TIP);
setStateToolTip(volButton, volState, VOL_TOOL_TIP); setStateToolTip(volButton, volState, VOL_TOOL_TIP);
setStateToolTip(searchButton, searchState, SEARCH_TOOL_TIP);
} }
void ChatFormHeader::updateButtonsView() void ChatFormHeader::updateButtonsView()
@ -199,7 +188,6 @@ void ChatFormHeader::updateButtonsView()
setStateName(videoButton, videoState); setStateName(videoButton, videoState);
setStateName(micButton, micState); setStateName(micButton, micState);
setStateName(volButton, volState); setStateName(volButton, volState);
setStateName(searchButton, searchState);
retranslateUi(); retranslateUi();
Style::repolish(this); Style::repolish(this);
} }
@ -281,17 +269,6 @@ void ChatFormHeader::updateMuteVolButton(bool active, bool outputMuted)
updateButtonsView(); updateButtonsView();
} }
void ChatFormHeader::updateSearchButton(bool active)
{
if (active) {
searchState = ToolButtonState::On;
} else {
searchState = ToolButtonState::Off;
}
updateButtonsView();
}
void ChatFormHeader::setAvatar(const QPixmap &img) void ChatFormHeader::setAvatar(const QPixmap &img)
{ {
avatar->setPixmap(img); avatar->setPixmap(img);

4
src/widget/chatformheader.h

@ -67,7 +67,6 @@ public:
void updateCallButtons(bool online, bool audio, bool video = false); void updateCallButtons(bool online, bool audio, bool video = false);
void updateMuteMicButton(bool active, bool inputMuted); void updateMuteMicButton(bool active, bool inputMuted);
void updateMuteVolButton(bool active, bool outputMuted); void updateMuteVolButton(bool active, bool outputMuted);
void updateSearchButton(bool active);
void setAvatar(const QPixmap& img); void setAvatar(const QPixmap& img);
QSize getAvatarSize() const; QSize getAvatarSize() const;
@ -82,7 +81,6 @@ signals:
void videoCallTriggered(); void videoCallTriggered();
void micMuteToggle(); void micMuteToggle();
void volMuteToggle(); void volMuteToggle();
void searchTriggered();
void nameChanged(const QString& name); void nameChanged(const QString& name);
@ -104,13 +102,11 @@ private:
QPushButton* videoButton; QPushButton* videoButton;
QPushButton* volButton; QPushButton* volButton;
QPushButton* micButton; QPushButton* micButton;
QPushButton* searchButton;
CallButtonState callState; CallButtonState callState;
CallButtonState videoState; CallButtonState videoState;
ToolButtonState volState; ToolButtonState volState;
ToolButtonState micState; ToolButtonState micState;
ToolButtonState searchState;
std::unique_ptr<CallConfirmWidget> callConfirm; std::unique_ptr<CallConfirmWidget> callConfirm;
}; };

24
src/widget/form/chatform.cpp

@ -178,11 +178,11 @@ ChatForm::ChatForm(Friend* chatFriend, History* history)
connect(headWidget, &ChatFormHeader::videoCallTriggered, this, &ChatForm::onVideoCallTriggered); connect(headWidget, &ChatFormHeader::videoCallTriggered, this, &ChatForm::onVideoCallTriggered);
connect(headWidget, &ChatFormHeader::micMuteToggle, this, &ChatForm::onMicMuteToggle); connect(headWidget, &ChatFormHeader::micMuteToggle, this, &ChatForm::onMicMuteToggle);
connect(headWidget, &ChatFormHeader::volMuteToggle, this, &ChatForm::onVolMuteToggle); connect(headWidget, &ChatFormHeader::volMuteToggle, this, &ChatForm::onVolMuteToggle);
connect(headWidget, &ChatFormHeader::searchTriggered, this, &ChatForm::onSearchTrigered);
connect(searchForm, &SearchForm::searchInBegin, this, &ChatForm::earchInBegin); connect(searchForm, &SearchForm::searchInBegin, this, &ChatForm::searchInBegin);
connect(searchForm, &SearchForm::searchUp, this, &ChatForm::onSearchUp); connect(searchForm, &SearchForm::searchUp, this, &ChatForm::onSearchUp);
connect(searchForm, &SearchForm::searchDown, this, &ChatForm::onSearchDown); connect(searchForm, &SearchForm::searchDown, this, &ChatForm::onSearchDown);
connect(searchForm, &SearchForm::visibleChanged, this, &ChatForm::onSearchTrigered);
connect(msgEdit, &ChatTextEdit::enterPressed, this, &ChatForm::onSendTriggered); connect(msgEdit, &ChatTextEdit::enterPressed, this, &ChatForm::onSendTriggered);
connect(msgEdit, &ChatTextEdit::textChanged, this, &ChatForm::onTextEditChanged); connect(msgEdit, &ChatTextEdit::textChanged, this, &ChatForm::onTextEditChanged);
@ -498,21 +498,17 @@ void ChatForm::onVolMuteToggle()
void ChatForm::onSearchTrigered() void ChatForm::onSearchTrigered()
{ {
if (searchForm->maximumHeight() == 0) { if (searchForm->isHidden()) {
searchForm->setMaximumHeight(50);
headWidget->updateSearchButton(true);
searchPoint = QPoint(1, -1);
searchAfterLoadHistory = false;
} else {
searchForm->setMaximumHeight(0);
searchForm->removeSearchPhrase(); searchForm->removeSearchPhrase();
headWidget->updateSearchButton(false);
desibleSearchText(); desibleSearchText();
} else {
searchPoint = QPoint(1, -1);
searchAfterLoadHistory = false;
} }
} }
void ChatForm::earchInBegin(const QString &phrase) void ChatForm::searchInBegin(const QString &phrase)
{ {
desibleSearchText(); desibleSearchText();
@ -609,8 +605,12 @@ void ChatForm::onSearchDown(const QString &phrase)
} }
QVector<ChatLine::Ptr> lines = chatWidget->getLines(); QVector<ChatLine::Ptr> lines = chatWidget->getLines();
int numLines = lines.size();
if (lines.isEmpty()) {
return;
}
int numLines = lines.size();
int startLine = numLines - searchPoint.x(); int startLine = numLines - searchPoint.x();
for (int i = startLine; i < numLines; ++i) { for (int i = startLine; i < numLines; ++i) {

2
src/widget/form/chatform.h

@ -89,7 +89,7 @@ private slots:
void onVolMuteToggle(); void onVolMuteToggle();
void onSearchTrigered(); void onSearchTrigered();
void earchInBegin(const QString& phrase); void searchInBegin(const QString& phrase);
void onSearchUp(const QString& phrase); void onSearchUp(const QString& phrase);
void onSearchDown(const QString& phrase); void onSearchDown(const QString& phrase);
void onContinueSearch(); void onContinueSearch();

18
src/widget/form/genericchatform.cpp

@ -139,7 +139,7 @@ GenericChatForm::GenericChatForm(QWidget* parent)
searchForm = new SearchForm(); searchForm = new SearchForm();
chatWidget = new ChatLog(this); chatWidget = new ChatLog(this);
chatWidget->setBusyNotification(ChatMessage::createBusyNotification()); chatWidget->setBusyNotification(ChatMessage::createBusyNotification());
searchForm->setMaximumHeight(0); searchForm->hide();
// settings // settings
const Settings& s = Settings::getInstance(); const Settings& s = Settings::getInstance();
@ -202,6 +202,12 @@ GenericChatForm::GenericChatForm(QWidget* parent)
addAction(quoteAction); addAction(quoteAction);
menu.addSeparator(); menu.addSeparator();
searchAction = menu.addAction(QIcon(), QString(), this, SLOT(searchFormShow()),
QKeySequence(Qt::CTRL + Qt::Key_F));
addAction(searchAction);
menu.addSeparator();
menu.addActions(chatWidget->actions()); menu.addActions(chatWidget->actions());
menu.addSeparator(); menu.addSeparator();
@ -297,7 +303,7 @@ void GenericChatForm::showEvent(QShowEvent*)
bool GenericChatForm::event(QEvent* e) bool GenericChatForm::event(QEvent* e)
{ {
// If the user accidentally starts typing outside of the msgEdit, focus it automatically // If the user accidentally starts typing outside of the msgEdit, focus it automatically
if (searchForm->maximumHeight() == 0) { if (searchForm->isHidden()) {
if (e->type() == QEvent::KeyRelease && !msgEdit->hasFocus()) { if (e->type() == QEvent::KeyRelease && !msgEdit->hasFocus()) {
QKeyEvent* ke = static_cast<QKeyEvent*>(e); QKeyEvent* ke = static_cast<QKeyEvent*>(e);
if ((ke->modifiers() == Qt::NoModifier || ke->modifiers() == Qt::ShiftModifier) if ((ke->modifiers() == Qt::NoModifier || ke->modifiers() == Qt::ShiftModifier)
@ -668,6 +674,13 @@ void GenericChatForm::copyLink()
QApplication::clipboard()->setText(linkText); QApplication::clipboard()->setText(linkText);
} }
void GenericChatForm::searchFormShow()
{
if (searchForm->isHidden()) {
searchForm->show();
}
}
void GenericChatForm::retranslateUi() void GenericChatForm::retranslateUi()
{ {
sendButton->setToolTip(tr("Send message")); sendButton->setToolTip(tr("Send message"));
@ -678,6 +691,7 @@ void GenericChatForm::retranslateUi()
clearAction->setText(tr("Clear displayed messages")); clearAction->setText(tr("Clear displayed messages"));
quoteAction->setText(tr("Quote selected text")); quoteAction->setText(tr("Quote selected text"));
copyLinkAction->setText(tr("Copy link address")); copyLinkAction->setText(tr("Copy link address"));
searchAction->setText(tr("Search in text"));
} }
void GenericChatForm::showNetcam() void GenericChatForm::showNetcam()

2
src/widget/form/genericchatform.h

@ -103,6 +103,7 @@ protected slots:
void onSplitterMoved(int pos, int index); void onSplitterMoved(int pos, int index);
void quoteSelectedText(); void quoteSelectedText();
void copyLink(); void copyLink();
void searchFormShow();
private: private:
void retranslateUi(); void retranslateUi();
@ -134,6 +135,7 @@ protected:
QAction* clearAction; QAction* clearAction;
QAction* quoteAction; QAction* quoteAction;
QAction* copyLinkAction; QAction* copyLinkAction;
QAction* searchAction;
ToxPk previousId; ToxPk previousId;

25
src/widget/searchform.cpp

@ -39,15 +39,24 @@ SearchForm::SearchForm(QWidget *parent) : QWidget(parent)
downButton->setProperty("state", "green"); downButton->setProperty("state", "green");
downButton->setStyleSheet(Style::getStylesheet(QStringLiteral(":/ui/chatForm/buttons.css"))); downButton->setStyleSheet(Style::getStylesheet(QStringLiteral(":/ui/chatForm/buttons.css")));
hideButton = new QPushButton();
hideButton->setAttribute(Qt::WA_LayoutUsesWidgetRect);
hideButton->setObjectName("hideButton");
hideButton->setProperty("state", "red");
hideButton->setStyleSheet(Style::getStylesheet(QStringLiteral(":/ui/chatForm/buttons.css")));
layout->setMargin(0);
layout->addWidget(searchLine); layout->addWidget(searchLine);
layout->addWidget(upButton); layout->addWidget(upButton);
layout->addWidget(downButton); layout->addWidget(downButton);
layout->addWidget(hideButton);
setLayout(layout); setLayout(layout);
connect(searchLine, &QLineEdit::textChanged, this, &SearchForm::changedSearchPhrare); connect(searchLine, &QLineEdit::textChanged, this, &SearchForm::changedSearchPhrase);
connect(upButton, &QPushButton::clicked, this, &SearchForm::clickedUp); connect(upButton, &QPushButton::clicked, this, &SearchForm::clickedUp);
connect(downButton, &QPushButton::clicked, this, &SearchForm::clickedDown); connect(downButton, &QPushButton::clicked, this, &SearchForm::clickedDown);
connect(hideButton, &QPushButton::clicked, this, &SearchForm::clickedHide);
} }
void SearchForm::removeSearchPhrase() void SearchForm::removeSearchPhrase()
@ -60,7 +69,13 @@ QString SearchForm::getSearchPhrase() const
return searchPhrase; return searchPhrase;
} }
void SearchForm::changedSearchPhrare(const QString &text) void SearchForm::showEvent(QShowEvent *event)
{
QWidget::showEvent(event);
emit visibleChanged();
}
void SearchForm::changedSearchPhrase(const QString &text)
{ {
searchPhrase = text; searchPhrase = text;
emit searchInBegin(searchPhrase); emit searchInBegin(searchPhrase);
@ -75,3 +90,9 @@ void SearchForm::clickedDown()
{ {
emit searchDown(searchPhrase); emit searchDown(searchPhrase);
} }
void SearchForm::clickedHide()
{
hide();
emit visibleChanged();
}

8
src/widget/searchform.h

@ -36,19 +36,25 @@ public:
private: private:
QPushButton* upButton; QPushButton* upButton;
QPushButton* downButton; QPushButton* downButton;
QPushButton* hideButton;
QLineEdit* searchLine; QLineEdit* searchLine;
QString searchPhrase; QString searchPhrase;
protected:
virtual void showEvent(QShowEvent *event);
private slots: private slots:
void changedSearchPhrare(const QString &text); void changedSearchPhrase(const QString &text);
void clickedUp(); void clickedUp();
void clickedDown(); void clickedDown();
void clickedHide();
signals: signals:
void searchInBegin(const QString &); void searchInBegin(const QString &);
void searchUp(const QString &); void searchUp(const QString &);
void searchDown(const QString &); void searchDown(const QString &);
void visibleChanged();
}; };
#endif // SEARCHFORM_H #endif // SEARCHFORM_H

12
ui/chatForm/buttons.css

@ -67,16 +67,16 @@ QAbstractButton#callButton
height: 40px; height: 40px;
} }
QAbstractButton#searchButton /* SearchLine */
QAbstractButton#hideButton
{ {
background-image: url(":/ui/chatForm/searchButton.svg"); background-image: url(":/ui/chatForm/hideButton.svg");
border-radius: 5px; border-radius: 5px;
width: 50px; width: 35px;
height: 40px; height: 35px;
} }
/* SearchLine */
QAbstractButton#searchUpButton QAbstractButton#searchUpButton
{ {

55
ui/chatForm/searchButton.svg → ui/chatForm/hideButton.svg

@ -9,13 +9,13 @@
xmlns="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="8.5557709mm" width="5.5071211mm"
height="5.0002112mm" height="5.5071211mm"
viewBox="0 0 8.555771 5.0002106" viewBox="0 0 5.5071209 5.5071212"
version="1.1" version="1.1"
id="svg8" id="svg8"
inkscape:version="0.92.2 5c3e80d, 2017-08-06" inkscape:version="0.92.2 5c3e80d, 2017-08-06"
sodipodi:docname="searchButton.svg"> sodipodi:docname="hideButton.svg">
<defs <defs
id="defs2" /> id="defs2" />
<sodipodi:namedview <sodipodi:namedview
@ -25,9 +25,9 @@
borderopacity="1.0" borderopacity="1.0"
inkscape:pageopacity="0.0" inkscape:pageopacity="0.0"
inkscape:pageshadow="2" inkscape:pageshadow="2"
inkscape:zoom="22.4" inkscape:zoom="2.8"
inkscape:cx="21.984681" inkscape:cx="186.40227"
inkscape:cy="2.8941014" inkscape:cy="-38.76831"
inkscape:document-units="mm" inkscape:document-units="mm"
inkscape:current-layer="layer1" inkscape:current-layer="layer1"
showgrid="false" showgrid="false"
@ -39,12 +39,7 @@
inkscape:window-height="1015" inkscape:window-height="1015"
inkscape:window-x="0" inkscape:window-x="0"
inkscape:window-y="876" inkscape:window-y="876"
inkscape:window-maximized="1" inkscape:window-maximized="1" />
showguides="false">
<inkscape:grid
type="xygrid"
id="grid40" />
</sodipodi:namedview>
<metadata <metadata
id="metadata5"> id="metadata5">
<rdf:RDF> <rdf:RDF>
@ -61,26 +56,26 @@
inkscape:label="Layer 1" inkscape:label="Layer 1"
inkscape:groupmode="layer" inkscape:groupmode="layer"
id="layer1" id="layer1"
transform="translate(340.51327,202.78083)"> transform="translate(59.891963,-41.449704)">
<g <g
id="g38" id="g30"
transform="translate(-6.0476191,-0.34254092)" transform="matrix(0.42362466,0.42362466,-0.42362466,0.42362466,-22.854056,42.277356)"
style="fill:#ffffff"> style="fill:#ffffff">
<path
id="path12"
transform="matrix(0.26458333,0,0,0.26458333,-340.91,-203.00001)"
d="m 47.244141,2.1230469 a 9.4488189,9.4488189 0 0 0 -9.449219,9.4492191 9.4488189,9.4488189 0 0 0 9.449219,9.449218 9.4488189,9.4488189 0 0 0 9.449218,-9.449218 9.4488189,9.4488189 0 0 0 -9.449218,-9.4492191 z m 0,3.4023437 a 6.0472442,6.0472442 0 0 1 6.046875,6.0468754 6.0472442,6.0472442 0 0 1 -6.046875,6.046875 6.0472442,6.0472442 0 0 1 -6.046875,-6.046875 6.0472442,6.0472442 0 0 1 6.046875,-6.0468754 z"
style="fill:#ffffff;stroke-width:1.0102793"
inkscape:connector-curvature="0" />
<rect <rect
ry="0.64999998" y="41.988605"
transform="rotate(-15)" x="-43.942345"
y="-278.625" height="1.5"
x="-271.75787" width="11.5"
height="1.3" id="rect11"
width="4.5002789" style="fill:#ffffff;stroke-width:0.26458332" />
id="rect32" <rect
style="fill:#ffffff;stroke-width:0.26111853" /> transform="rotate(-90)"
y="-38.942345"
x="-48.488605"
height="1.5"
width="11.500001"
id="rect11-3"
style="fill:#ffffff;stroke-width:0.26458332" />
</g> </g>
</g> </g>
</svg> </svg>

Before

Width:  |  Height:  |  Size: 2.8 KiB

After

Width:  |  Height:  |  Size: 2.3 KiB

Loading…
Cancel
Save