_chatViewSearchController, SLOT(setSearchMsgs(bool)));
connect(ui.searchBar->searchOnlyRegularMsgsBox(), SIGNAL(toggled(bool)),
_chatViewSearchController, SLOT(setSearchOnlyRegularMsgs(bool)));
+ connect(ui.searchBar->searchUpButton(), SIGNAL(clicked()),
+ _chatViewSearchController, SLOT(highlightPrev()));
+ connect(ui.searchBar->searchDownButton(), SIGNAL(clicked()),
+ _chatViewSearchController, SLOT(highlightNext()));
+
+ connect(_chatViewSearchController, SIGNAL(newCurrentHighlight(QGraphicsItem *)),
+ this, SLOT(scrollToHighlight(QGraphicsItem *)));
}
BufferWidget::~BufferWidget() {
}
}
+void BufferWidget::scrollToHighlight(QGraphicsItem *highlightItem) {
+ ChatView *view = qobject_cast<ChatView *>(ui.stackedWidget->currentWidget());
+ if(view) {
+ view->centerOn(highlightItem);
+ }
+}
#include "abstractbuffercontainer.h"
+class QGraphicsItem;
class ChatViewSearchBar;
class ChatViewSearchController;
class BufferWidget : public AbstractBufferContainer {
Q_OBJECT
- public:
- BufferWidget(QWidget *parent);
- ~BufferWidget();
+public:
+ BufferWidget(QWidget *parent);
+ ~BufferWidget();
inline ChatViewSearchBar *searchBar() const { return ui.searchBar; }
- protected:
- virtual AbstractChatView *createChatView(BufferId);
- virtual void removeChatView(BufferId);
+protected:
+ virtual AbstractChatView *createChatView(BufferId);
+ virtual void removeChatView(BufferId);
- protected slots:
- virtual void showChatView(BufferId);
+protected slots:
+ virtual void showChatView(BufferId);
- private:
- Ui::BufferWidget ui;
- QHash<BufferId, QWidget *> _chatViews;
+private slots:
+ void scrollToHighlight(QGraphicsItem *highlightItem);
+
+private:
+ Ui::BufferWidget ui;
+ QHash<BufferId, QWidget *> _chatViews;
ChatViewSearchController *_chatViewSearchController;
};
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setAlignment(Qt::AlignBottom);
setInteractive(true);
- setOptimizationFlags(QGraphicsView::DontClipPainter | QGraphicsView::DontAdjustForAntialiasing);
+ //setOptimizationFlags(QGraphicsView::DontClipPainter | QGraphicsView::DontAdjustForAntialiasing);
+ setOptimizationFlags(QGraphicsView::DontAdjustForAntialiasing);
setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate);
setTransformationAnchor(QGraphicsView::NoAnchor);
ui.setupUi(this);
layout()->setContentsMargins(0, 0, 0, 0);
- ui.searchUpButton->setEnabled(false);
- ui.searchDownButton->setEnabled(false);
-
hide();
ActionCollection *coll = QtUi::actionCollection();
inline QCheckBox *searchSendersBox() const { return ui.searchSendersBox; }
inline QCheckBox *searchMsgsBox() const { return ui.searchMsgsBox; }
inline QCheckBox *searchOnlyRegularMsgsBox() const { return ui.searchOnlyRegularMsgsBox; }
+ inline QToolButton *searchUpButton() const { return ui.searchUpButton; }
+ inline QToolButton *searchDownButton() const { return ui.searchDownButton; }
public slots:
void setVisible(bool);
ChatViewSearchController::ChatViewSearchController(QObject *parent)
: QObject(parent),
_scene(0),
+ _currentHighlight(0),
_caseSensitive(false),
_searchSenders(false),
_searchMsgs(true),
updateHighlights();
}
+void ChatViewSearchController::highlightNext() {
+ if(_highlightItems.isEmpty())
+ return;
+
+ if(_currentHighlight < _highlightItems.count()) {
+ _highlightItems.at(_currentHighlight)->setHighlighted(false);
+ }
+ _currentHighlight++;
+ if(_currentHighlight >= _highlightItems.count())
+ _currentHighlight = 0;
+ _highlightItems.at(_currentHighlight)->setHighlighted(true);
+ emit newCurrentHighlight(_highlightItems.at(_currentHighlight));
+}
+
+void ChatViewSearchController::highlightPrev() {
+ if(_highlightItems.isEmpty())
+ return;
+
+ if(_currentHighlight < _highlightItems.count()) {
+ _highlightItems.at(_currentHighlight)->setHighlighted(false);
+ }
+
+ _currentHighlight--;
+ if(_currentHighlight < 0)
+ _currentHighlight = _highlightItems.count() - 1;
+ _highlightItems.at(_currentHighlight)->setHighlighted(true);
+ emit newCurrentHighlight(_highlightItems.at(_currentHighlight));
+}
void ChatViewSearchController::updateHighlights(bool reuse) {
if(!_scene)
highlightLine(line);
}
}
+
+ if(!_highlightItems.isEmpty()) {
+ _highlightItems.last()->setHighlighted(true);
+ _currentHighlight = _highlightItems.count() - 1;
+ emit newCurrentHighlight(_highlightItems.last());
+ }
}
void ChatViewSearchController::highlightLine(ChatLine *line) {
updateHighlights(searchOnlyRegularMsgs);
}
+
+// ==================================================
+// SearchHighlightItem
+// ==================================================
SearchHighlightItem::SearchHighlightItem(QRectF wordRect, QGraphicsItem *parent)
- : QGraphicsItem(parent)
+ : QObject(),
+ QGraphicsItem(parent),
+ _highlighted(false),
+ _alpha(100),
+ _timeLine(150)
{
setPos(wordRect.x(), wordRect.y());
qreal sizedelta = wordRect.height() * 0.1;
_boundingRect = QRectF(-sizedelta, -sizedelta, wordRect.width() + 2 * sizedelta, wordRect.height() + 2 * sizedelta);
+
+ connect(&_timeLine, SIGNAL(valueChanged(qreal)), this, SLOT(updateHighlight(qreal)));
+}
+
+void SearchHighlightItem::setHighlighted(bool highlighted) {
+ _highlighted = highlighted;
+
+ if(highlighted)
+ _timeLine.setDirection(QTimeLine::Forward);
+ else
+ _timeLine.setDirection(QTimeLine::Backward);
+
+ if(_timeLine.state() != QTimeLine::Running)
+ _timeLine.start();
+
+ update();
+}
+
+void SearchHighlightItem::updateHighlight(qreal value) {
+ _alpha = 100 + 155 * value;
+ update();
}
void SearchHighlightItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) {
Q_UNUSED(option);
Q_UNUSED(widget);
- painter->setPen(QPen(Qt::black, 1.5));
- painter->setBrush(QColor(254, 237, 45));
+ painter->setPen(QPen(QColor(0, 0, 0, _alpha), 1.5));
+ painter->setBrush(QColor(254, 237, 45, _alpha));
painter->setRenderHints(QPainter::Antialiasing);
qreal radius = boundingRect().height() * 0.30;
painter->drawRoundedRect(boundingRect(), radius, radius);
#include <QHash>
#include <QPointer>
#include <QString>
+#include <QTimeLine>
#include "message.h"
+class QGraphicsItem;
class ChatLine;
class ChatScene;
class SearchHighlightItem;
void setSearchMsgs(bool searchMsgs);
void setSearchOnlyRegularMsgs(bool searchOnlyRegularMsgs);
+ void highlightNext();
+ void highlightPrev();
+
private slots:
void sceneDestroyed();
void updateHighlights(bool reuse = false);
+signals:
+ void newCurrentHighlight(QGraphicsItem *highlightItem);
+
private:
QString _searchString;
ChatScene *_scene;
QList<SearchHighlightItem *> _highlightItems;
+ int _currentHighlight;
bool _caseSensitive;
bool _searchSenders;
// Highlight Items
#include <QGraphicsItem>
-class SearchHighlightItem : public QGraphicsItem {
+class SearchHighlightItem : public QObject, public QGraphicsItem {
+ Q_OBJECT
+
public:
SearchHighlightItem(QRectF wordRect, QGraphicsItem *parent = 0);
inline virtual QRectF boundingRect() const { return _boundingRect; }
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
+ void setHighlighted(bool highlighted);
+
+private slots:
+ void updateHighlight(qreal value);
private:
QRectF _boundingRect;
+ bool _highlighted;
+ qreal _alpha;
+ QTimeLine _timeLine;
};
#endif //CHATVIEWSEARCHCONTROLLER_H