File indexing completed on 2024-05-12 04:58:18
0001 /* ============================================================ 0002 * Falkon - Qt web browser 0003 * Copyright (C) 2010-2018 David Rosca <nowrep@gmail.com> 0004 * 0005 * This program is free software: you can redistribute it and/or modify 0006 * it under the terms of the GNU General Public License as published by 0007 * the Free Software Foundation, either version 3 of the License, or 0008 * (at your option) any later version. 0009 * 0010 * This program is distributed in the hope that it will be useful, 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0013 * GNU General Public License for more details. 0014 * 0015 * You should have received a copy of the GNU General Public License 0016 * along with this program. If not, see <http://www.gnu.org/licenses/>. 0017 * ============================================================ */ 0018 #include "popupstatusbarmessage.h" 0019 #include "popupwindow.h" 0020 #include "popupwebview.h" 0021 #include "webpage.h" 0022 #include "mainapplication.h" 0023 0024 #include <QStatusBar> 0025 #include <QStyle> 0026 0027 PopupStatusBarMessage::PopupStatusBarMessage(PopupWindow* window) 0028 : m_popupWindow(window) 0029 , m_statusBarText(new TipLabel(window)) 0030 { 0031 } 0032 0033 void PopupStatusBarMessage::showMessage(const QString &message) 0034 { 0035 if (m_popupWindow->statusBar()->isVisible()) { 0036 m_popupWindow->statusBar()->showMessage(message); 0037 } 0038 #ifdef Q_OS_WIN 0039 else if (mApp->activeWindow() == m_popupWindow) { 0040 #else 0041 else { 0042 #endif 0043 PopupWebView* view = m_popupWindow->webView(); 0044 0045 m_statusBarText->setText(message); 0046 m_statusBarText->setMaximumWidth(view->width()); 0047 m_statusBarText->resize(m_statusBarText->sizeHint()); 0048 0049 QPoint position; 0050 position.setY(view->height() - m_statusBarText->height()); 0051 0052 QRect statusRect = QRect(view->mapToGlobal(QPoint(0, position.y())), m_statusBarText->size()); 0053 0054 if (statusRect.contains(QCursor::pos())) { 0055 position.setY(position.y() - m_statusBarText->height()); 0056 } 0057 0058 m_statusBarText->move(view->mapToGlobal(position)); 0059 m_statusBarText->show(view); 0060 } 0061 } 0062 0063 void PopupStatusBarMessage::clearMessage() 0064 { 0065 if (m_popupWindow->statusBar()->isVisible()) { 0066 m_popupWindow->statusBar()->showMessage(QString()); 0067 } 0068 else { 0069 m_statusBarText->hideDelayed(); 0070 } 0071 }