Skip to content
This repository has been archived by the owner on Feb 12, 2023. It is now read-only.

Commit

Permalink
feat: remove search button and add line in context menu
Browse files Browse the repository at this point in the history
  • Loading branch information
TriKriSta committed Feb 11, 2018
1 parent de9c906 commit 8bb80c7
Show file tree
Hide file tree
Showing 11 changed files with 96 additions and 85 deletions.
2 changes: 1 addition & 1 deletion res.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@
<file>img/caps_lock.svg</file>
<file>ui/contentDialog/contentDialog.css</file>
<file>ui/tooliconsZone/tooliconsZone.css</file>
<file>ui/chatForm/searchButton.svg</file>
<file>ui/chatForm/searchDownButton.svg</file>
<file>ui/chatForm/searchUpButton.svg</file>
<file>ui/chatForm/hideButton.svg</file>
</qresource>
</RCC>
29 changes: 3 additions & 26 deletions src/widget/chatformheader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,6 @@ const QString MIC_TOOL_TIP[] = {
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>
QPushButton* createButton(const QString& name, T* self, Fun onClickSlot)
{
Expand Down Expand Up @@ -117,7 +111,6 @@ ChatFormHeader::ChatFormHeader(QWidget* parent)
, videoState{CallButtonState::Disabled}
, volState{ToolButtonState::Disabled}
, micState{ToolButtonState::Disabled}
, searchState{ToolButtonState::Off}
{
QHBoxLayout* headLayout = new QHBoxLayout();
avatar = new MaskablePixmapWidget(this, AVATAR_SIZE, ":/img/avatar_mask.svg");
Expand All @@ -139,18 +132,16 @@ ChatFormHeader::ChatFormHeader(QWidget* parent)
volButton = createButton("volButton", this, &ChatFormHeader::volMuteToggle);
callButton = createButton("callButton", this, &ChatFormHeader::callTriggered);
videoButton = createButton("videoButton", this, &ChatFormHeader::videoCallTriggered);
searchButton = createButton("searchButton", this, &ChatFormHeader::searchTriggered);

QVBoxLayout* micButtonsLayout = new QVBoxLayout();
micButtonsLayout->setSpacing(MIC_BUTTONS_LAYOUT_SPACING);
micButtonsLayout->addWidget(micButton, Qt::AlignTop | Qt::AlignRight);
micButtonsLayout->addWidget(volButton, Qt::AlignTop | Qt::AlignRight);

QGridLayout* buttonsLayout = new QGridLayout();
buttonsLayout->addWidget(searchButton, 0, 0, 2, 1, Qt::AlignTop);
buttonsLayout->addLayout(micButtonsLayout, 0, 1, 2, 1, Qt::AlignTop | Qt::AlignRight);
buttonsLayout->addWidget(callButton, 0, 2, 2, 1, Qt::AlignTop);
buttonsLayout->addWidget(videoButton, 0, 3, 2, 1, Qt::AlignTop);
buttonsLayout->addLayout(micButtonsLayout, 0, 0, 2, 1, Qt::AlignTop | Qt::AlignRight);
buttonsLayout->addWidget(callButton, 0, 1, 2, 1, Qt::AlignTop);
buttonsLayout->addWidget(videoButton, 0, 2, 2, 1, Qt::AlignTop);
buttonsLayout->setVerticalSpacing(0);
buttonsLayout->setHorizontalSpacing(BUTTONS_LAYOUT_HOR_SPACING);

Expand Down Expand Up @@ -180,7 +171,6 @@ void ChatFormHeader::setMode(ChatFormHeader::Mode mode)
videoButton->hide();
volButton->hide();
micButton->hide();
searchButton->hide();
}
}

Expand All @@ -190,7 +180,6 @@ void ChatFormHeader::retranslateUi()
setStateToolTip(videoButton, videoState, VIDEO_TOOL_TIP);
setStateToolTip(micButton, micState, MIC_TOOL_TIP);
setStateToolTip(volButton, volState, VOL_TOOL_TIP);
setStateToolTip(searchButton, searchState, SEARCH_TOOL_TIP);
}

void ChatFormHeader::updateButtonsView()
Expand All @@ -199,7 +188,6 @@ void ChatFormHeader::updateButtonsView()
setStateName(videoButton, videoState);
setStateName(micButton, micState);
setStateName(volButton, volState);
setStateName(searchButton, searchState);
retranslateUi();
Style::repolish(this);
}
Expand Down Expand Up @@ -281,17 +269,6 @@ void ChatFormHeader::updateMuteVolButton(bool active, bool outputMuted)
updateButtonsView();
}

void ChatFormHeader::updateSearchButton(bool active)
{
if (active) {
searchState = ToolButtonState::On;
} else {
searchState = ToolButtonState::Off;
}

updateButtonsView();
}

void ChatFormHeader::setAvatar(const QPixmap &img)
{
avatar->setPixmap(img);
Expand Down
4 changes: 0 additions & 4 deletions src/widget/chatformheader.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ class ChatFormHeader : public QWidget
void updateCallButtons(bool online, bool audio, bool video = false);
void updateMuteMicButton(bool active, bool inputMuted);
void updateMuteVolButton(bool active, bool outputMuted);
void updateSearchButton(bool active);

void setAvatar(const QPixmap& img);
QSize getAvatarSize() const;
Expand All @@ -82,7 +81,6 @@ class ChatFormHeader : public QWidget
void videoCallTriggered();
void micMuteToggle();
void volMuteToggle();
void searchTriggered();

void nameChanged(const QString& name);

Expand All @@ -104,13 +102,11 @@ private slots:
QPushButton* videoButton;
QPushButton* volButton;
QPushButton* micButton;
QPushButton* searchButton;

CallButtonState callState;
CallButtonState videoState;
ToolButtonState volState;
ToolButtonState micState;
ToolButtonState searchState;

std::unique_ptr<CallConfirmWidget> callConfirm;
};
Expand Down
24 changes: 12 additions & 12 deletions src/widget/form/chatform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,11 @@ ChatForm::ChatForm(Friend* chatFriend, History* history)
connect(headWidget, &ChatFormHeader::videoCallTriggered, this, &ChatForm::onVideoCallTriggered);
connect(headWidget, &ChatFormHeader::micMuteToggle, this, &ChatForm::onMicMuteToggle);
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::searchDown, this, &ChatForm::onSearchDown);
connect(searchForm, &SearchForm::visibleChanged, this, &ChatForm::onSearchTrigered);

connect(msgEdit, &ChatTextEdit::enterPressed, this, &ChatForm::onSendTriggered);
connect(msgEdit, &ChatTextEdit::textChanged, this, &ChatForm::onTextEditChanged);
Expand Down Expand Up @@ -498,21 +498,17 @@ void ChatForm::onVolMuteToggle()

void ChatForm::onSearchTrigered()
{
if (searchForm->maximumHeight() == 0) {
searchForm->setMaximumHeight(50);
headWidget->updateSearchButton(true);
searchPoint = QPoint(1, -1);
searchAfterLoadHistory = false;
} else {
searchForm->setMaximumHeight(0);
if (searchForm->isHidden()) {
searchForm->removeSearchPhrase();
headWidget->updateSearchButton(false);

desibleSearchText();
} else {
searchPoint = QPoint(1, -1);
searchAfterLoadHistory = false;
}
}

void ChatForm::earchInBegin(const QString &phrase)
void ChatForm::searchInBegin(const QString &phrase)
{
desibleSearchText();

Expand Down Expand Up @@ -609,8 +605,12 @@ void ChatForm::onSearchDown(const QString &phrase)
}

QVector<ChatLine::Ptr> lines = chatWidget->getLines();
int numLines = lines.size();

if (lines.isEmpty()) {
return;
}

int numLines = lines.size();
int startLine = numLines - searchPoint.x();

for (int i = startLine; i < numLines; ++i) {
Expand Down
2 changes: 1 addition & 1 deletion src/widget/form/chatform.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ private slots:
void onVolMuteToggle();
void onSearchTrigered();

void earchInBegin(const QString& phrase);
void searchInBegin(const QString& phrase);
void onSearchUp(const QString& phrase);
void onSearchDown(const QString& phrase);
void onContinueSearch();
Expand Down
18 changes: 16 additions & 2 deletions src/widget/form/genericchatform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ GenericChatForm::GenericChatForm(QWidget* parent)
searchForm = new SearchForm();
chatWidget = new ChatLog(this);
chatWidget->setBusyNotification(ChatMessage::createBusyNotification());
searchForm->setMaximumHeight(0);
searchForm->hide();

// settings
const Settings& s = Settings::getInstance();
Expand Down Expand Up @@ -202,6 +202,12 @@ GenericChatForm::GenericChatForm(QWidget* parent)
addAction(quoteAction);
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.addSeparator();

Expand Down Expand Up @@ -297,7 +303,7 @@ void GenericChatForm::showEvent(QShowEvent*)
bool GenericChatForm::event(QEvent* e)
{
// 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()) {
QKeyEvent* ke = static_cast<QKeyEvent*>(e);
if ((ke->modifiers() == Qt::NoModifier || ke->modifiers() == Qt::ShiftModifier)
Expand Down Expand Up @@ -668,6 +674,13 @@ void GenericChatForm::copyLink()
QApplication::clipboard()->setText(linkText);
}

void GenericChatForm::searchFormShow()
{
if (searchForm->isHidden()) {
searchForm->show();
}
}

void GenericChatForm::retranslateUi()
{
sendButton->setToolTip(tr("Send message"));
Expand All @@ -678,6 +691,7 @@ void GenericChatForm::retranslateUi()
clearAction->setText(tr("Clear displayed messages"));
quoteAction->setText(tr("Quote selected text"));
copyLinkAction->setText(tr("Copy link address"));
searchAction->setText(tr("Search in text"));
}

void GenericChatForm::showNetcam()
Expand Down
2 changes: 2 additions & 0 deletions src/widget/form/genericchatform.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ protected slots:
void onSplitterMoved(int pos, int index);
void quoteSelectedText();
void copyLink();
void searchFormShow();

private:
void retranslateUi();
Expand Down Expand Up @@ -134,6 +135,7 @@ protected slots:
QAction* clearAction;
QAction* quoteAction;
QAction* copyLinkAction;
QAction* searchAction;

ToxPk previousId;

Expand Down
25 changes: 23 additions & 2 deletions src/widget/searchform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,24 @@ SearchForm::SearchForm(QWidget *parent) : QWidget(parent)
downButton->setProperty("state", "green");
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(upButton);
layout->addWidget(downButton);
layout->addWidget(hideButton);

setLayout(layout);

connect(searchLine, &QLineEdit::textChanged, this, &SearchForm::changedSearchPhrare);
connect(searchLine, &QLineEdit::textChanged, this, &SearchForm::changedSearchPhrase);
connect(upButton, &QPushButton::clicked, this, &SearchForm::clickedUp);
connect(downButton, &QPushButton::clicked, this, &SearchForm::clickedDown);
connect(hideButton, &QPushButton::clicked, this, &SearchForm::clickedHide);
}

void SearchForm::removeSearchPhrase()
Expand All @@ -60,7 +69,13 @@ QString SearchForm::getSearchPhrase() const
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;
emit searchInBegin(searchPhrase);
Expand All @@ -75,3 +90,9 @@ void SearchForm::clickedDown()
{
emit searchDown(searchPhrase);
}

void SearchForm::clickedHide()
{
hide();
emit visibleChanged();
}
8 changes: 7 additions & 1 deletion src/widget/searchform.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,25 @@ class SearchForm final : public QWidget
private:
QPushButton* upButton;
QPushButton* downButton;
QPushButton* hideButton;
QLineEdit* searchLine;

QString searchPhrase;

protected:
virtual void showEvent(QShowEvent *event);

private slots:
void changedSearchPhrare(const QString &text);
void changedSearchPhrase(const QString &text);
void clickedUp();
void clickedDown();
void clickedHide();

signals:
void searchInBegin(const QString &);
void searchUp(const QString &);
void searchDown(const QString &);
void visibleChanged();
};

#endif // SEARCHFORM_H
12 changes: 6 additions & 6 deletions ui/chatForm/buttons.css
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,16 @@ QAbstractButton#callButton
height: 40px;
}

QAbstractButton#searchButton
/* SearchLine */

QAbstractButton#hideButton
{
background-image: url(":/ui/chatForm/searchButton.svg");
background-image: url(":/ui/chatForm/hideButton.svg");
border-radius: 5px;
width: 50px;
height: 40px;
width: 35px;
height: 35px;
}

/* SearchLine */


QAbstractButton#searchUpButton
{
Expand Down
Loading

0 comments on commit 8bb80c7

Please sign in to comment.