along with Situare; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
USA.
- */
+ */
+
+ #include <QHBoxLayout>
+ #include <QLabel>
+ #include <QPushButton>
-#include "../user/user.h"
#include "coordinates/geocoordinate.h"
#include "friendlistitem.h"
#include "friendlistitemdelegate.h"
connect(m_clearFilterButton, SIGNAL(clicked()),
this, SLOT(clearFriendListFilter()));
- // connect(this, SIGNAL(panelOpened()),
- // this, SLOT(clearFriendListFilter()));
+ connect(m_routeButton, SIGNAL(clicked()),
+ this, SLOT(routeToSelectedFriend()));
+
+ /// @todo remove old filterLayout when new panel are merged
+
+ //////////////////////////////////////////////////////////////////////////
+ // NOTE! Do not mix the new filtering layout below with the old one above
+ //////////////////////////////////////////////////////////////////////////
+
+ // filtering layout
+ QHBoxLayout *filteringLayout = new QHBoxLayout();
+ friendListPanelLayout->addLayout(filteringLayout);
+
+ // line edit for filtering
+ m_filterField = new QLineEdit;
+ filteringLayout->addWidget(m_filterField);
+
+ connect(m_filterField, SIGNAL(returnPressed()),
+ this, SLOT(clearFiltering()));
+
+ connect(m_filterField, SIGNAL(textChanged(QString)),
+ this, SLOT(filterTextChanged(QString)));
+
+ // button for clearing the filtering
+ m_filterClearButton = new QPushButton();
+ filteringLayout->addWidget(m_filterClearButton);
+ m_filterClearButton->setIcon(QIcon::fromTheme(QLatin1String("general_close")));
+
+ connect(m_filterClearButton, SIGNAL(clicked()),
+ this, SLOT(clearFiltering()));
+
+ connect(qApp, SIGNAL(topmostWindowChanged(bool)),
+ this, SLOT(topmostWindowChanged(bool)));
+}
+
+void FriendListPanel::clearFiltering()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ ///< @todo Clear the filtering when fried list panel is closed (no hideEvent dispatched)
+
+ // clearing the filtering text field does cause also hiding the filtering layout
+ m_filterField->clear();
+}
+
+void FriendListPanel::clearFriendListFilter()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ m_friendListHeaderWidget->hide();
+ m_friendListView->clearFilter();
+}
+
+void FriendListPanel::filterTextChanged(const QString &text)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ if (m_filterField->isHidden() && !text.isEmpty())
+ setFilteringLayoutVisibility(true);
+ else if (m_filterField->isVisible() && text.isEmpty())
+ setFilteringLayoutVisibility(false);
+
+ m_friendListView->filter(text);
}
void FriendListPanel::friendImageReady(User *user)
m_friendListView->clearUnused(newUserIDs);
}
-void FriendListPanel::clearFriendListFilter()
+void FriendListPanel::hideEvent(QHideEvent *event)
{
- qDebug() << __PRETTY_FUNCTION__;
+ qWarning() << __PRETTY_FUNCTION__;
- m_friendListHeaderWidget->hide();
- m_friendListView->clearFilter();
+ QWidget::hideEvent(event);
+ updateKeyboardGrabbing();
+ clearFiltering();
}
+ void FriendListPanel::routeToSelectedFriend()
+ {
+ qDebug() << __PRETTY_FUNCTION__;
+
+ FriendListItem *item = dynamic_cast<FriendListItem *>(m_friendListView->selectedItem());
+
+ if (item)
+ emit routeToFriend(item->coordinates());
+ }
+
+void FriendListPanel::setFilteringLayoutVisibility(bool visible)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ m_filterField->setVisible(visible);
+ m_filterClearButton->setVisible(visible);
+}
+
+void FriendListPanel::updateKeyboardGrabbing()
+{
+ qWarning() << __PRETTY_FUNCTION__;
+
+ if (!m_mainWindowIsTopmost || !isVisible()) {
+ if (QWidget::keyboardGrabber() == m_filterField) {
+ m_filterField->releaseKeyboard();
+ qWarning() << __PRETTY_FUNCTION__ << "released";
+ }
+ } else if (m_mainWindowIsTopmost && isVisible()) {
+ if (QWidget::keyboardGrabber() != m_filterField) {
+ m_filterField->grabKeyboard();
+ qWarning() << __PRETTY_FUNCTION__ << "grabbed";
+ }
+ }
+}
+
+void FriendListPanel::showEvent(QShowEvent *event)
+{
+ qWarning() << __PRETTY_FUNCTION__;
+
+ QWidget::showEvent(event);
+ updateKeyboardGrabbing();
+ setFilteringLayoutVisibility(false);
+}
+
void FriendListPanel::showFriendsInList(const QList<QString> &userIDs)
{
qDebug() << __PRETTY_FUNCTION__;
m_friendListLabel->setText(tr("Selected: %1").arg(userIDs.count()));
- // openPanel();
m_friendListHeaderWidget->show();
m_friendListView->filter(userIDs);
+
+ emit showPanelRequested(this);
}
+
+void FriendListPanel::topmostWindowChanged(bool mainWindowIsTopmost)
+{
+ qWarning() << __PRETTY_FUNCTION__ << mainWindowIsTopmost;
+
+ m_mainWindowIsTopmost = mainWindowIsTopmost;
+ updateKeyboardGrabbing();
+}
*/
void friendInfoReceived(QList<User *> &friendList);
+private:
+ /**
+ * @brief Set visibility for filtering related UI elements
+ *
+ * @param visible True if items should be visible, false if not
+ */
+ void setFilteringLayoutVisibility(bool visible);
+
+ /**
+ * @brief Takes care of grabbing and releasing the keyboard when required
+ *
+ * Keyboard is grabbed when MainWindow it the topmost window and FriendListPanel is visible.
+ * Releasing is done if the MainWindow is not the topmost window and/or FriendListPanel
+ * is invisible.
+ */
+ void updateKeyboardGrabbing();
+
private slots:
/**
- * @brief Slot to clear friend list filter.
+ * @brief Slot to clear friend list filter
*/
void clearFriendListFilter();
/**
+ * @brief Slot for clearing the friend list filtering.
+ */
+ void clearFiltering();
+
+ /**
+ * @brief Set filtering UI elements visibility based on the filtering text value
+ *
+ * Filtering UI elements are invoked when the text becomes not empty and hidden when text
+ * becomes empty.
+ *
+ * @param text New text value
+ */
+ void filterTextChanged(const QString &text);
+
+ /**
- * @brief Called when topmost window is changed
- *
- * Does set m_mainWindowIsTopmost and calls updateKeyboardGrabbing()
+ * @brief Routes to selected friend.
*
- * @param mainWindowIsTopmost True if MainWindow is the topmost one
+ * Emits routeToFriend if friend is selected from list.
*/
- void topmostWindowChanged(bool mainWindowIsTopmost);
+ void routeToSelectedFriend();
/**
- * @brief Slot to show friends in list
+ * @brief Slot to show friends in list.
*
- * Shows only friends that are on userIDs list.
+ * Shows only friends that are on userIDs list
* @param userIDs list of user ID's
*/
void showFriendsInList(const QList<QString> &userIDs);
++ /**
++ * @brief Called when topmost window is changed
++ *
++ * Does set m_mainWindowIsTopmost and calls updateKeyboardGrabbing()
++ *
++ * @param mainWindowIsTopmost True if MainWindow is the topmost one
++ */
++ void topmostWindowChanged(bool mainWindowIsTopmost);
++
/*******************************************************************************
* SIGNALS
******************************************************************************/
* DATA MEMBERS
******************************************************************************/
private:
- QLabel *m_friendListLabel; ///< Friend list label
+ bool m_mainWindowIsTopmost; ///< Is the MainWindow the topmost one
+ QLabel *m_friendListLabel; ///< Friend list label
++
+ QLineEdit *m_filterField; ///< Text field for the filter text
++
QPushButton *m_clearFilterButton; ///< Button to clear list filtering
+ QPushButton *m_filterClearButton; ///< Button for clearing the filtering
+ QPushButton *m_routeButton; ///< Button to route to friend
+
QWidget *m_friendListHeaderWidget; ///< Friend list header widget
FriendListView *m_friendListView; ///< Friend list view