|
|
|
@ -118,7 +118,19 @@ IWin* MdiManager::createSubwindow(IWin* parent, const QString& buttonText, IWin: |
|
|
|
|
mdiwin->setAttribute(Qt::WA_DeleteOnClose); |
|
|
|
|
m_bbMgr.addButton(basePtr, mdiwin); |
|
|
|
|
|
|
|
|
|
QRect spawnCoord = generateSpawnCoordinates(); |
|
|
|
|
QString networkKey, windowKey; |
|
|
|
|
if (windowType == IWin::Type::Channel || windowType == IWin::Type::Private) { |
|
|
|
|
const auto& connection = dynamic_cast<IWinStatus*>(parent)->getConnection(); |
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
networkKey = QString::fromStdString(connection.isupport().at("NETWORK")); |
|
|
|
|
} |
|
|
|
|
catch (...) {} |
|
|
|
|
|
|
|
|
|
windowKey = buttonText; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
QRect spawnCoord = generateSpawnCoordinates(networkKey, windowKey); |
|
|
|
|
mdiwin->setGeometry(spawnCoord); |
|
|
|
|
|
|
|
|
|
qInfo() << "Created a subwindow of type" << IWin::TypeString[windowType] << "with button text" << buttonText; |
|
|
|
@ -209,7 +221,7 @@ int MdiManager::connectionsOnlineCount() const |
|
|
|
|
IWin* subwin = dynamic_cast<IWin*>(mdiwin->widget()); |
|
|
|
|
if (subwin->getType() != IWin::Type::Status) |
|
|
|
|
continue; |
|
|
|
|
IWinStatus* status = dynamic_cast<IWinStatus*>(subwin); |
|
|
|
|
auto* status = dynamic_cast<IWinStatus*>(subwin); |
|
|
|
|
if (status->getConnection().isOnline()) |
|
|
|
|
++c; |
|
|
|
|
} |
|
|
|
@ -220,18 +232,19 @@ void MdiManager::broadcastProgramExit() |
|
|
|
|
{ |
|
|
|
|
for (QMdiSubWindow* mdiwin : m_mdiArea.subWindowList()) { |
|
|
|
|
IWin* subwin = dynamic_cast<IWin*>(mdiwin->widget()); |
|
|
|
|
if (subwin->getType() != IWin::Type::Status) |
|
|
|
|
continue; |
|
|
|
|
IWinStatus* status = dynamic_cast<IWinStatus*>(subwin); |
|
|
|
|
if (status->getConnection().isOnline()) { |
|
|
|
|
connect(&status->getConnection(), &IRC::readyForExit, [this](){ |
|
|
|
|
if (connectionsOnlineCount() == 0) |
|
|
|
|
emit readyForExit(); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
ConfigMgr& conf = ConfigMgr::instance(); |
|
|
|
|
status->getConnection().disconnectForExit(conf.common("QuitMessage")); |
|
|
|
|
} |
|
|
|
|
if (subwin->getType() == IWin::Type::Status) { |
|
|
|
|
auto* status = dynamic_cast<IWinStatus*>(subwin); |
|
|
|
|
if (status->getConnection().isOnline()) { |
|
|
|
|
connect(&status->getConnection(), &IRC::readyForExit, |
|
|
|
|
[this]() { |
|
|
|
|
if (connectionsOnlineCount() == 0) |
|
|
|
|
emit readyForExit(); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
ConfigMgr& conf = ConfigMgr::instance(); |
|
|
|
|
status->getConnection().disconnectForExit(conf.common("QuitMessage")); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -321,19 +334,64 @@ void MdiManager::subwinActivated(QMdiSubWindow* window) |
|
|
|
|
emit subwindowSwitched(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
QRect MdiManager::generateSpawnCoordinates() |
|
|
|
|
QRect MdiManager::generateSpawnCoordinates(const QString& networkKey, const QString& windowKey) |
|
|
|
|
{ |
|
|
|
|
QRect rectangle(nextXY, nextXY, WINDOW_DEFAULT_WIDTH, WINDOW_DEFAULT_HEIGHT); |
|
|
|
|
nextXY += WINDOW_STEP; |
|
|
|
|
|
|
|
|
|
if (nextXY > WINDOW_STEP_RESET_POSITION) { |
|
|
|
|
nextXYadjust += WINDOW_STEP_RESET_ADJUST; |
|
|
|
|
if (nextXYadjust > WINDOW_STEP_RESET_POSITION) |
|
|
|
|
nextXYadjust = 0; |
|
|
|
|
|
|
|
|
|
nextXY = nextXYadjust; |
|
|
|
|
} |
|
|
|
|
auto generate = [this] { |
|
|
|
|
QRect rectangle(nextXY, nextXY, WINDOW_DEFAULT_WIDTH, WINDOW_DEFAULT_HEIGHT); |
|
|
|
|
nextXY += WINDOW_STEP; |
|
|
|
|
|
|
|
|
|
if (nextXY > WINDOW_STEP_RESET_POSITION) { |
|
|
|
|
nextXYadjust += WINDOW_STEP_RESET_ADJUST; |
|
|
|
|
if (nextXYadjust > WINDOW_STEP_RESET_POSITION) |
|
|
|
|
nextXYadjust = 0; |
|
|
|
|
|
|
|
|
|
nextXY = nextXYadjust; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return rectangle; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
if (windowKey.isEmpty()) { |
|
|
|
|
return generate(); |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
auto persistentKey = QStringLiteral("%1_%2") |
|
|
|
|
.arg(networkKey) |
|
|
|
|
.arg(windowKey); |
|
|
|
|
if (networkKey.isEmpty()) |
|
|
|
|
persistentKey = windowKey; |
|
|
|
|
|
|
|
|
|
const auto& conf = ConfigMgr::instance(); |
|
|
|
|
auto geometryString = conf.window(persistentKey); |
|
|
|
|
if (geometryString.isEmpty()) { |
|
|
|
|
/*
|
|
|
|
|
* If the key (persistentKey) doesn't exist, check config if any window name that isn't |
|
|
|
|
* tied to any network name exist, and use that. |
|
|
|
|
*/ |
|
|
|
|
geometryString = conf.window(windowKey); |
|
|
|
|
if (geometryString.isEmpty()) |
|
|
|
|
return generate(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
QStringList geometry = geometryString.split(','); |
|
|
|
|
if (geometry.count() < 4) { |
|
|
|
|
qWarning() << "Configuration for subwindow geometry '" << persistentKey << "' is invalid, resolving using generic positioning algorithm."; |
|
|
|
|
return generate(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const int X = geometry[0].toInt(); |
|
|
|
|
const int Y = geometry[1].toInt(); |
|
|
|
|
const int W = geometry[2].toInt(); |
|
|
|
|
const int H = geometry[3].toInt(); |
|
|
|
|
return { X, Y, W, H }; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return rectangle; |
|
|
|
|
QList<QMdiSubWindow*> MdiManager::mdiChildren() const |
|
|
|
|
{ |
|
|
|
|
QList<QMdiSubWindow*> ret; |
|
|
|
|
for (QMdiSubWindow* mdiwin : m_mdiArea.subWindowList()) |
|
|
|
|
ret << mdiwin; |
|
|
|
|
return ret; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|