From 31d198a7a9b8c1fdda0ab4ec8dbd3bf79f5346b1 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Thu, 21 Aug 2014 15:37:12 -0700 Subject: [PATCH 1/3] Remove custom behavior from chat window --- interface/src/ui/ChatWindow.cpp | 24 ++++++------- interface/src/ui/ChatWindow.h | 2 +- interface/ui/chatWindow.ui | 62 ++------------------------------- 3 files changed, 15 insertions(+), 73 deletions(-) diff --git a/interface/src/ui/ChatWindow.cpp b/interface/src/ui/ChatWindow.cpp index 8874f18dba..8c37cc6a70 100644 --- a/interface/src/ui/ChatWindow.cpp +++ b/interface/src/ui/ChatWindow.cpp @@ -30,16 +30,14 @@ const int NUM_MESSAGES_TO_TIME_STAMP = 20; -const float OPACITY_ACTIVE = 1.0f; -const float OPACITY_INACTIVE = 0.8f; - const QRegularExpression regexLinks("((?:(?:ftp)|(?:https?)|(?:hifi))://\\S+)"); const QRegularExpression regexHifiLinks("([#@]\\S+)"); const QString mentionSoundsPath("/mention-sounds/"); const QString mentionRegex("@(\\b%1\\b)"); ChatWindow::ChatWindow(QWidget* parent) : - FramelessDialog(parent, 0, POSITION_RIGHT), + QWidget(parent, Qt::Window | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowMinMaxButtonsHint | + Qt::WindowCloseButtonHint), ui(new Ui::ChatWindow), numMessagesAfterLastTimeStamp(0), _mousePressed(false), @@ -82,7 +80,6 @@ ChatWindow::ChatWindow(QWidget* parent) : startTimerForTimeStamps(); } else { ui->numOnlineLabel->hide(); - ui->closeButton->hide(); ui->usersArea->hide(); ui->messagesScrollArea->hide(); ui->messagePlainTextEdit->hide(); @@ -113,17 +110,21 @@ void ChatWindow::keyPressEvent(QKeyEvent* event) { if (event->key() == Qt::Key_Escape) { Application::getInstance()->getWindow()->activateWindow(); } else { - FramelessDialog::keyPressEvent(event); + QWidget::keyPressEvent(event); } } void ChatWindow::showEvent(QShowEvent* event) { - FramelessDialog::showEvent(event); + QWidget::showEvent(event); if (!event->spontaneous()) { ui->messagePlainTextEdit->setFocus(); } + const QRect parentGeometry = parentWidget()->geometry(); + setGeometry(parentGeometry.topRight().x() - size().width(), parentGeometry.topRight().y(), + size().width(), parentWidget()->height()); + #ifdef HAVE_QXMPP const QXmppClient& xmppClient = XmppClient::getInstance().getXMPPClient(); if (xmppClient.isConnected()) { @@ -163,7 +164,7 @@ bool ChatWindow::eventFilter(QObject* sender, QEvent* event) { return true; } } - return FramelessDialog::eventFilter(sender, event); + return QWidget::eventFilter(sender, event); } void ChatWindow::addTimeStamp() { @@ -210,7 +211,6 @@ void ChatWindow::startTimerForTimeStamps() { void ChatWindow::connected() { ui->connectingToXMPPLabel->hide(); ui->numOnlineLabel->show(); - ui->closeButton->show(); ui->usersArea->show(); ui->messagesScrollArea->show(); ui->messagePlainTextEdit->show(); @@ -389,9 +389,7 @@ void ChatWindow::scrollToBottom() { bool ChatWindow::event(QEvent* event) { if (event->type() == QEvent::WindowActivate) { - setWindowOpacity(OPACITY_ACTIVE); - } else if (event->type() == QEvent::WindowDeactivate) { - setWindowOpacity(OPACITY_INACTIVE); + ui->messagePlainTextEdit->setFocus(); } - return FramelessDialog::event(event); + return QWidget::event(event); } diff --git a/interface/src/ui/ChatWindow.h b/interface/src/ui/ChatWindow.h index 652dcb5b08..afaacf34b4 100644 --- a/interface/src/ui/ChatWindow.h +++ b/interface/src/ui/ChatWindow.h @@ -38,7 +38,7 @@ const int AUTO_SCROLL_THRESHOLD = 20; class ChatWindow; } -class ChatWindow : public FramelessDialog { +class ChatWindow : public QWidget { Q_OBJECT public: diff --git a/interface/ui/chatWindow.ui b/interface/ui/chatWindow.ui index 46ccafd5f8..4120515b3d 100644 --- a/interface/ui/chatWindow.ui +++ b/interface/ui/chatWindow.ui @@ -1,7 +1,7 @@ ChatWindow - + 0 @@ -86,45 +86,6 @@ - - - - - 0 - 0 - - - - - 16 - 16 - - - - Qt::NoFocus - - - QPushButton { - background-color: rgba( 0, 0, 0, 0% ); - border: none; - image: url(../resources/images/close.svg) -} - - -QPushButton:pressed { - background-color: rgba( 0, 0, 0, 0% ); - border: none; - image: url(../resources/images/close_down.svg) -} - - - - - - true - - - @@ -283,7 +244,7 @@ border-color: palette(dark); border-style: solid; border-left-width: 1px; borde QAbstractScrollArea::AdjustToContents - true + true false @@ -308,22 +269,5 @@ border-color: palette(dark); border-style: solid; border-left-width: 1px; borde messagesScrollArea - - - closeButton - clicked() - ChatWindow - hide() - - - 390 - 42 - - - 550 - 42 - - - - + From 51e616d12224b82e03a2ce3936f22ca4b5538313 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Thu, 4 Sep 2014 07:20:27 -0700 Subject: [PATCH 2/3] Add margin to chat window for titlebar + menu --- interface/src/Menu.cpp | 5 +++++ interface/src/ui/ChatWindow.cpp | 14 +++++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index 0dcfd60051..a2e572dd9e 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -1456,7 +1456,9 @@ void Menu::showChat() { if (_chatWindow->isHidden()) { _chatWindow->show(); } + _chatWindow->raise(); _chatWindow->activateWindow(); + _chatWindow->setFocus(); } else { Application::getInstance()->getTrayIcon()->showMessage("Interface", "You need to login to be able to chat with others on this domain."); } @@ -1468,6 +1470,9 @@ void Menu::toggleChat() { if (!_chatAction->isEnabled() && _chatWindow && AccountManager::getInstance().isLoggedIn()) { if (_chatWindow->isHidden()) { _chatWindow->show(); + _chatWindow->raise(); + _chatWindow->activateWindow(); + _chatWindow->setFocus(); } else { _chatWindow->hide(); } diff --git a/interface/src/ui/ChatWindow.cpp b/interface/src/ui/ChatWindow.cpp index 8c37cc6a70..5253e0958e 100644 --- a/interface/src/ui/ChatWindow.cpp +++ b/interface/src/ui/ChatWindow.cpp @@ -18,12 +18,13 @@ #include #include "Application.h" +#include "ChatMessageArea.h" #include "FlowLayout.h" #include "qtimespan.h" -#include "ui_chatWindow.h" +#include "UIUtil.h" #include "XmppClient.h" -#include "ChatMessageArea.h" +#include "ui_chatWindow.h" #include "ChatWindow.h" @@ -120,10 +121,13 @@ void ChatWindow::showEvent(QShowEvent* event) { if (!event->spontaneous()) { ui->messagePlainTextEdit->setFocus(); } - const QRect parentGeometry = parentWidget()->geometry(); - setGeometry(parentGeometry.topRight().x() - size().width(), parentGeometry.topRight().y(), - size().width(), parentWidget()->height()); + int titleBarHeight = UIUtil::getWindowTitleBarHeight(this); + int menuBarHeight = Menu::getInstance()->geometry().height(); + int topMargin = titleBarHeight + menuBarHeight; + + setGeometry(parentGeometry.topRight().x() - size().width() + 1, parentGeometry.topRight().y() + topMargin, + size().width(), parentWidget()->height() - topMargin); #ifdef HAVE_QXMPP const QXmppClient& xmppClient = XmppClient::getInstance().getXMPPClient(); From 2b5759bb3991d0fd61a262480abc7f4b656f9460 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Thu, 4 Sep 2014 10:53:51 -0700 Subject: [PATCH 3/3] Update chat to close on ESC --- interface/src/ui/ChatWindow.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/interface/src/ui/ChatWindow.cpp b/interface/src/ui/ChatWindow.cpp index 5253e0958e..47c29a30a9 100644 --- a/interface/src/ui/ChatWindow.cpp +++ b/interface/src/ui/ChatWindow.cpp @@ -110,6 +110,7 @@ ChatWindow::~ChatWindow() { void ChatWindow::keyPressEvent(QKeyEvent* event) { if (event->key() == Qt::Key_Escape) { Application::getInstance()->getWindow()->activateWindow(); + hide(); } else { QWidget::keyPressEvent(event); }