#define _WANT_OPTION_FLAGS_
#include "KviOptions.h"
-#include <QSplitter>
-#include <QVariant>
-#include <QLineEdit>
-#include <QMessageBox>
-#include <QTimer>
-#include <QLayout>
+#include <QCheckBox>
+#include <QCloseEvent>
#include <QDesktopWidget>
#include <QEvent>
-#include <QCloseEvent>
-#include <QShortcut>
#include <QFile>
+#include <QLayout>
+#include <QLineEdit>
#include <QMenu>
-#include <QWindowStateChangeEvent>
-#include <QCheckBox>
+#include <QMessageBox>
+#include <QShortcut>
+#include <QSplitter>
#include <QString>
+#include <QTimer>
+#include <QVariant>
+#include <QWindowStateChangeEvent>
-#include <ctime>
#include <algorithm>
+#include <ctime>
#ifdef COMPILE_PSEUDO_TRANSPARENCY
#include <QPixmap>
setWindowTitle(KVI_DEFAULT_FRAME_CAPTION);
- m_pActiveContext = nullptr;
-
- m_pTrayIcon = nullptr;
-
m_pSplitter = new QSplitter(Qt::Horizontal, this);
m_pSplitter->setObjectName("main_frame_splitter");
m_pSplitter->setChildrenCollapsible(false);
// the init function)
m_pStatusBar->load();
}
- else
- {
- m_pStatusBar = nullptr;
- }
-
- m_pWindowList = nullptr;
createWindowList();
delete m_pStatusBar;
m_pStatusBar = nullptr;
- std::vector<KviWindow *> l_winListCopy(m_WinList.begin(), m_WinList.end());
- std::vector<KviWindow *>::size_type iCount = 0;
-
- // close all not console windows
- while(iCount < l_winListCopy.size())
- {
- KviWindow * lkWindow = l_winListCopy[iCount];
- if(lkWindow->type() != KviWindow::Console)
- {
- closeWindow(lkWindow);
- l_winListCopy.erase(l_winListCopy.begin() + iCount);
- }
- else
- {
- ++iCount;
- }
- }
+ std::vector<KviWindow *> lWinListCopy(m_WinList.begin(), m_WinList.end());
+ // Sort the console windows to the end so they are closed last
+ std::sort(begin(lWinListCopy), end(lWinListCopy), [](KviWindow * a, KviWindow * b){
+ return !a->isConsole() && b->isConsole();
+ });
- // close all the remaining windows (consoles)
- for(auto & i : l_winListCopy)
+ for(auto & i : lWinListCopy)
closeWindow(i);
g_pMainWindow = nullptr;
for(auto & t : m_pModuleExtensionToolBarList)
{
QString s = t->descriptor()->module()->name();
- s += ":";
+ s += ':';
s += t->descriptor()->name().ptr();
- //qDebug("FOUND TOOLBAR %s",t.descriptor()->name().ptr());
-
KVI_OPTION_STRINGLIST(KviOption_stringlistModuleExtensionToolbars).append(s);
}
}
KviMexToolBar * KviMainWindow::moduleExtensionToolBar(int extensionId)
{
for(auto & t : m_pModuleExtensionToolBarList)
- {
if(extensionId == t->descriptor()->id())
return t;
- }
+
return nullptr;
}
m_pAccellerators.push_back(KviShortcut::create(key, this, SLOT(accelActivated()), SLOT(accelActivated()), Qt::ApplicationShortcut));
}
-void KviMainWindow::freeAccelleratorKeySequence(QString & key)
+void KviMainWindow::freeAccelleratorKeySequence(const QString & key)
{
QKeySequence kS(key);
for(auto & pS : m_pAccellerators)
void KviMainWindow::accelActivated()
{
- KVS_TRIGGER_EVENT_1(KviEvent_OnAccelKeyPressed, g_pActiveWindow, (((QShortcut *)sender())->key()).toString());
+ KVS_TRIGGER_EVENT_1(KviEvent_OnAccelKeyPressed, g_pActiveWindow, ((qobject_cast<QShortcut *>(sender()))->key()).toString());
}
void KviMainWindow::executeInternalCommand(int index)
void KviMainWindow::closeWindow(KviWindow * wnd)
{
- if(wnd->inherits("KviConsoleWindow"))
+ if(wnd->isConsole() && consoleCount() <= 1)
{
- if(consoleCount() <= 1)
- {
- KVS_TRIGGER_EVENT_0(KviEvent_OnFrameWindowDestroyed, wnd);
- KVS_TRIGGER_EVENT_0(KviEvent_OnKVIrcShutdown, wnd);
- }
+ KVS_TRIGGER_EVENT_0(KviEvent_OnFrameWindowDestroyed, wnd);
+ KVS_TRIGGER_EVENT_0(KviEvent_OnKVIrcShutdown, wnd);
}
// notify the destruction
wnd->triggerDestructionEvents();
// save it's properties
- if(KVI_OPTION_BOOL(KviOption_boolWindowsRememberProperties)) // && (wnd->type() == KviWindow::Channel))
+ if(KVI_OPTION_BOOL(KviOption_boolWindowsRememberProperties))
{
QString group;
wnd->getConfigGroupName(group);
if (iter != m_WinList.end())
m_WinList.erase(iter);
-#if 0
- // hide it
- if(wnd->parentWidget())
- wnd->mdiParent()->hide();
- else
- wnd->hide();
-#endif
-
if(wnd == g_pActiveWindow)
{
if(!g_pApp->kviClosingDown())
if(!bGotIt)
{
- // :/
g_pActiveWindow = nullptr;
m_pActiveContext = nullptr;
}
{
g_pWinPropertiesConfig->setGroup(group);
}
- else if(wnd->type() == KviWindow::Channel && g_pWinPropertiesConfig->hasGroup(group = wnd->windowName()))
+ else if(wnd->isChannel() && g_pWinPropertiesConfig->hasGroup(group = wnd->windowName()))
{
// try to load pre-4.2 channel settings
g_pWinPropertiesConfig->setGroup(group);
return c;
}
-unsigned int KviMainWindow::consoleCount()
+int KviMainWindow::consoleCount()
{
- unsigned int count = 0;
- for(auto & wnd : m_WinList)
- {
- if(wnd)
- if(wnd->type() == KviWindow::Console)
- count++;
- }
- return count;
+ return std::count_if(begin(m_WinList), end(m_WinList), [](KviWindow * w){ return w->isConsole(); });
}
KviConsoleWindow * KviMainWindow::firstConsole()
{
for(auto & wnd : m_WinList)
- {
- if(wnd->type() == KviWindow::Console)
- return (KviConsoleWindow *)wnd;
- }
+ if(wnd->isConsole())
+ return qobject_cast<KviConsoleWindow *>(wnd);
// We end up here when we have not console windows.
// This may happen at early startup or late before shutdown.
{
if(wnd->type() == KviWindow::Console)
{
- if(!((KviConsoleWindow *)wnd)->connectionInProgress())
- return (KviConsoleWindow *)wnd;
+ if(!qobject_cast<KviConsoleWindow *>(wnd)->connectionInProgress())
+ return qobject_cast<KviConsoleWindow *>(wnd);
}
}
return nullptr;
void KviMainWindow::setActiveWindow(KviWindow * wnd)
{
- // ASSERT(m_WinList.findRef(wnd))
m_pWindowStack->showAndActivate(wnd);
}
if(!wnd)
return; // this can happen?
- // ASSERT(m_WinList.findRef(wnd))
// unless we want to bForce the active window to be re-activated
if(g_pActiveWindow == wnd && !bForce)
return;
{
#ifndef COMPILE_ON_MAC
// For Qt5 this should be used to minimize to tray
- if(
- (e->type() == QEvent::WindowStateChange) && (windowState() & Qt::WindowMinimized) && KVI_OPTION_BOOL(KviOption_boolMinimizeInTray) && e->spontaneous())
+ if((e->type() == QEvent::WindowStateChange) && (windowState() & Qt::WindowMinimized) && KVI_OPTION_BOOL(KviOption_boolMinimizeInTray) && e->spontaneous())
{
if(!trayIcon())
}
if(trayIcon())
{
- QWindowStateChangeEvent * ev = (QWindowStateChangeEvent *)e;
+ QWindowStateChangeEvent * ev = static_cast<QWindowStateChangeEvent *>(e);
KVI_OPTION_BOOL(KviOption_boolFrameIsMaximized) = ev->oldState() & Qt::WindowMaximized;
- QTimer::singleShot(0, this, SLOT(hide()));
+ QTimer::singleShot(0, this, &KviMainWindow::hide);
}
return;
}
// and hopefully make the dock widget work correctly
// in this case.
// This will also trigger the OnWindowActivated event :)
- if(isActiveWindow())
+ if(g_pActiveWindow)
{
- if(g_pActiveWindow)
+ if(isActiveWindow())
windowActivated(g_pActiveWindow, true);
- }
- else
- {
- if(g_pActiveWindow)
+ else
g_pActiveWindow->lostUserFocus();
}
}
{
e->ignore();
KVI_OPTION_BOOL(KviOption_boolFrameIsMaximized) = isMaximized();
- QTimer::singleShot(0, this, SLOT(hide()));
+ QTimer::singleShot(0, this, &KviMainWindow::hide);
}
return;
}
bool bGotRunningConnection = false;
for(auto & w : m_WinList)
{
- if(w->type() == KviWindow::Console)
+ if(w->isConsole() && qobject_cast<KviConsoleWindow *>(w)->connectionInProgress())
{
- if(((KviConsoleWindow *)w)->connectionInProgress())
- {
- bGotRunningConnection = true;
- break;
- }
+ bGotRunningConnection = true;
+ break;
}
}
if(bGotRunningConnection)
{
- QString txt;
- txt += __tr2qs("There are active connections, are you sure you wish to quit KVIrc?");
+ QString txt = __tr2qs("There are active connections, are you sure you wish to quit KVIrc?");
switch(QMessageBox::warning(this, __tr2qs("Confirm Close - KVIrc"), txt, __tr2qs("&Yes"), __tr2qs("&Always"), __tr2qs("&No"), 2, 2))
{
if(trayIcon())
{
KVI_OPTION_BOOL(KviOption_boolFrameIsMaximized) = isMaximized();
- QTimer::singleShot(0, this, SLOT(hide()));
+ QTimer::singleShot(0, this, &KviMainWindow::hide);
}
return;
}
{
#ifdef COMPILE_PSEUDO_TRANSPARENCY
uint uOpacity = KVI_OPTION_UINT(KviOption_uintGlobalWindowOpacityPercent) < 50 ? 50 : KVI_OPTION_UINT(KviOption_uintGlobalWindowOpacityPercent);
- setWindowOpacity((float)uOpacity / 100);
+ setWindowOpacity(uOpacity / 100.f);
#if defined(COMPILE_ON_WINDOWS) || defined(COMPILE_ON_MINGW)
#ifndef Q_WS_EX_LAYERED
#define Q_WS_EX_LAYERED WS_EX_LAYERED
{
p->clear();
- disconnect(p, SIGNAL(triggered(QAction *)), this, SLOT(toolbarsPopupSelected(QAction *))); // just to be sure
- connect(p, SIGNAL(triggered(QAction *)), this, SLOT(toolbarsPopupSelected(QAction *)));
+ disconnect(p, &QMenu::triggered, this, &KviMainWindow::toolbarsPopupSelected); // just to be sure
+ connect(p, &QMenu::triggered, this, &KviMainWindow::toolbarsPopupSelected);
- QAction * pAction = nullptr;
int cnt = 0;
KviModuleExtensionDescriptorList * l = g_pModuleExtensionManager->getExtensionList("toolbar");
for(KviModuleExtensionDescriptor * d = l->first(); d; d = l->next())
{
QString label = __tr2qs("Show %1").arg(d->visibleName());
+ QAction * pAction;
if(d->icon())
pAction = p->addAction(*(d->icon()), label);
else
{
QString label = __tr2qs("Show %1").arg(d->label());
QString ico = d->iconId();
+ QAction * pAction;
if(!ico.isEmpty())
{
QPixmap * pix = g_pIconManager->getImage(d->iconId());
if(pix)
- {
pAction = p->addAction(*pix, label);
- }
else
- {
pAction = p->addAction(label);
- }
}
else
{
void KviMainWindow::toolbarsPopupSelected(QAction * pAction)
{
- bool bOk = false;
+ bool bOk;
int idext = pAction->data().toInt(&bOk);
if(!bOk)
return;
}
if(KviMexToolBar * t = moduleExtensionToolBar(idext))
- {
t->die();
- }
else
- {
g_pModuleExtensionManager->allocateExtension("toolbar", idext, firstConsole());
- }
}
void KviMainWindow::iconSizePopupSelected(QAction * pAction)
if(!pAction)
return;
- bool bOk = false;
+ bool bOk;
uint uSize = pAction->data().toUInt(&bOk);
if(!bOk)
return;
if(!pAction)
return;
- bool bOk = false;
+ bool bOk;
uint uStyle = pAction->data().toUInt(&bOk);
if(!bOk)
return;
bool KviMainWindow::focusNextPrevChild(bool next)
{
- QWidget * w = focusWidget();
- if(w)
+ if(QWidget * w = focusWidget(); w)
{
if(w->focusPolicy() == Qt::StrongFocus)
return false;
QFile f(szTemp);
if(f.open(QIODevice::WriteOnly | QIODevice::Truncate))
- {
f.write(saveState(1));
- }
}
void KviMainWindow::restoreToolBarPositions()
#include <unordered_set>
#include <vector>
-class KviMenuBar;
-class KviWindowStack;
-class KviWindow;
-class KviConsoleWindow;
-class KviWindowListBase;
-class QSplitter;
class KviConfigurationFile;
-class KviMexToolBar;
-class KviIrcContext;
+class KviConsoleWindow;
class KviIrcConnection;
+class KviIrcContext;
+class KviMenuBar;
+class KviMexToolBar;
class KviStatusBar;
-class QMenu;
class KviTrayIcon;
+class KviWindow;
+class KviWindowListBase;
+class KviWindowStack;
+class QMenu;
+class QSplitter;
class QShortcut;
class QString;
-class KVIRC_API KviMainWindow : public KviTalMainWindow //, public KviIrcContextManager
+class KVIRC_API KviMainWindow : public KviTalMainWindow
{
- friend class KviWindow;
- friend class KviConsoleWindow;
friend class KviApplication;
- friend class KviIrcServerParser;
- friend class KviMexToolBar;
- friend class KviWindowStack;
- friend class KviIrcContext;
+ friend class KviConsoleWindow;
friend class KviIrcConnection;
+ friend class KviIrcContext;
+ friend class KviIrcServerParser;
friend class KviLagMeter;
+ friend class KviMexToolBar;
+ friend class KviToolBar;
friend class KviUserListView;
friend class KviUserListViewArea;
+ friend class KviWindow;
+ friend class KviWindowStack;
Q_OBJECT
public:
KviMainWindow(QWidget * pParent);
KviMenuBar * m_pMenuBar; // the main menu bar
KviWindowStack * m_pWindowStack; // the mdi manager widget (child of the splitter)
std::unordered_set<KviMexToolBar *> m_pModuleExtensionToolBarList; // the module extension toolbars
- KviWindowListBase * m_pWindowList; // the WindowList
- KviStatusBar * m_pStatusBar;
+ KviWindowListBase * m_pWindowList = nullptr; // the WindowList
+ KviStatusBar * m_pStatusBar = nullptr;
// the mdi workspace child windows
std::list<KviWindow *> m_WinList; // the main list of windows
- KviIrcContext * m_pActiveContext; // the context of the m_pActiveWindow
+ KviIrcContext * m_pActiveContext = nullptr; // the context of the m_pActiveWindow
// other
- KviTrayIcon * m_pTrayIcon; // the frame's dock extension: this should be prolly moved ?
+ KviTrayIcon * m_pTrayIcon = nullptr; // the frame's dock extension: this should be prolly moved ?
std::vector<QShortcut *> m_pAccellerators; // global application accellerators
public:
// the mdi manager: handles mdi children
- KviWindowStack * windowStack() { return m_pWindowStack; };
+ KviWindowStack * windowStack() const { return m_pWindowStack; }
// the splitter is the central widget for this frame
- QSplitter * splitter() { return m_pSplitter; };
+ QSplitter * splitter() const { return m_pSplitter; }
// KviWindowListBase is the base class for KviTreeWindowList and the KviClassicWindowList
- KviWindowListBase * windowListWidget() { return m_pWindowList; };
+ KviWindowListBase * windowListWidget() const { return m_pWindowList; }
// well.. the menu bar :D
- KviMenuBar * mainMenuBar() { return m_pMenuBar; };
- KviStatusBar * mainStatusBar() { return m_pStatusBar; };
+ KviMenuBar * mainMenuBar() const { return m_pMenuBar; }
+ KviStatusBar * mainStatusBar() const { return m_pStatusBar; }
// this function may return nullptr if the active window has no irc context
- KviIrcContext * activeContext() { return m_pActiveContext; };
+ KviIrcContext * activeContext() const { return m_pActiveContext; }
// shortcut to a = activeContext(); return a ? a->connection() : 0
KviIrcConnection * activeConnection();
// The list of the windows belonging to this frame
// Note that the windows may be also undocked, but they are still owned by the frame
- std::list<KviWindow *> & windowList() { return m_WinList; };
+ std::list<KviWindow *> & windowList() { return m_WinList; }
// Sets the specified window to be the active one
// Raises it and focuses it
void setActiveWindow(KviWindow * wnd);
// window list. This is useful for asynchronous functions
// that keep a window pointer and need to ensure that it is still
// valid after an uncontrolled delay. (Think of a /timer implementation)
- bool windowExists(KviWindow * wnd) { return (std::find(m_WinList.begin(), m_WinList.end(), wnd) != m_WinList.end()); };
+ bool windowExists(KviWindow * wnd) const { return (std::find(m_WinList.begin(), m_WinList.end(), wnd) != m_WinList.end()); }
// The number of consoles in this frame
- unsigned int consoleCount();
+ int consoleCount();
// Creates a new console window. DON'T use the KviConsoleWindow constructor directly.
// (The script creation events are triggered from here)
KviConsoleWindow * createNewConsole(bool bFirstInFrame = false, bool bShowIt = true);
// This function CAN return nullptr if all the consoles are connected
KviConsoleWindow * firstNotConnectedConsole();
// this is explicitly dedicated to the TrayIcon module
- void setTrayIcon(KviTrayIcon * e) { m_pTrayIcon = e; };
+ void setTrayIcon(KviTrayIcon * e) { m_pTrayIcon = e; }
// returns the dockExtension applet. Useful for calling refresh() when
// some particular event happens
- KviTrayIcon * trayIcon() { return m_pTrayIcon; };
+ KviTrayIcon * trayIcon() const { return m_pTrayIcon; }
// helper for saving the window properties
void saveWindowProperties(KviWindow * wnd, const QString & szSection);
// finds the module extension toolbar with the specified identifier
void setIconSize(unsigned int uSize);
void setButtonStyle(unsigned int uStyle);
// allows scripts and actions to override builtin accellerators, avoiding ambiguous events
- void freeAccelleratorKeySequence(QString & key);
+ void freeAccelleratorKeySequence(const QString & key);
// called by children windows when they have updated their titles.
void updateWindowTitle(KviWindow * wnd);
public slots: