diff --git a/src/ViewSplitter.cpp b/src/ViewSplitter.cpp index e9a9cea7..8d384c41 100644 --- a/src/ViewSplitter.cpp +++ b/src/ViewSplitter.cpp @@ -1,279 +1,279 @@ /* This file is part of the Konsole Terminal. Copyright 2006-2008 Robert Knight This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ // Own #include "ViewSplitter.h" // Qt #include // Konsole #include "ViewContainer.h" using Konsole::ViewSplitter; using Konsole::TabbedViewContainer; ViewSplitter::ViewSplitter(QWidget *parent) : QSplitter(parent), _containers(QList()), _recursiveSplitting(true) { } void ViewSplitter::childEmpty(ViewSplitter *splitter) { delete splitter; if (count() == 0) { emit empty(this); } } void ViewSplitter::adjustContainerSize(TabbedViewContainer *container, int percentage) { int containerIndex = indexOf(container); Q_ASSERT(containerIndex != -1); QList containerSizes = sizes(); const int oldSize = containerSizes[containerIndex]; const auto newSize = static_cast(oldSize * (1.0 + percentage / 100.0)); const int perContainerDelta = (count() == 1) ? 0 : ((newSize - oldSize) / (count() - 1)) * (-1); for (int i = 0; i < containerSizes.count(); i++) { if (i == containerIndex) { containerSizes[i] = newSize; } else { containerSizes[i] = containerSizes[i] + perContainerDelta; } } setSizes(containerSizes); } ViewSplitter *ViewSplitter::activeSplitter() { QWidget *widget = focusWidget() != nullptr ? focusWidget() : this; ViewSplitter *splitter = nullptr; while ((splitter == nullptr) && (widget != nullptr)) { splitter = qobject_cast(widget); widget = widget->parentWidget(); } Q_ASSERT(splitter); return splitter; } void ViewSplitter::registerContainer(TabbedViewContainer *container) { _containers << container; - connect(container, SIGNAL(empty(TabbedViewContainer*)), this, SLOT(containerEmpty(TabbedViewContainer*))); + connect(container, &TabbedViewContainer::empty, this, &ViewSplitter::containerEmpty); } void ViewSplitter::unregisterContainer(TabbedViewContainer *container) { _containers.removeAll(container); disconnect(container, nullptr, this, nullptr); } void ViewSplitter::updateSizes() { int space; if (orientation() == Qt::Horizontal) { space = width() / count(); } else { space = height() / count(); } QList widgetSizes; const int widgetCount = count(); widgetSizes.reserve(widgetCount); for (int i = 0; i < widgetCount; i++) { widgetSizes << space; } setSizes(widgetSizes); } void ViewSplitter::setRecursiveSplitting(bool recursive) { _recursiveSplitting = recursive; } bool ViewSplitter::recursiveSplitting() const { return _recursiveSplitting; } void ViewSplitter::removeContainer(TabbedViewContainer *container) { Q_ASSERT(containers().contains(container)); unregisterContainer(container); } void ViewSplitter::addContainer(TabbedViewContainer *container, Qt::Orientation containerOrientation) { ViewSplitter *splitter = activeSplitter(); if (splitter->count() < 2 || containerOrientation == splitter->orientation() || !_recursiveSplitting) { splitter->registerContainer(container); splitter->addWidget(container); if (splitter->orientation() != containerOrientation) { splitter->setOrientation(containerOrientation); } splitter->updateSizes(); } else { auto newSplitter = new ViewSplitter(this); connect(newSplitter, &Konsole::ViewSplitter::empty, splitter, &Konsole::ViewSplitter::childEmpty); TabbedViewContainer *oldContainer = splitter->activeContainer(); const int oldContainerIndex = splitter->indexOf(oldContainer); splitter->unregisterContainer(oldContainer); newSplitter->registerContainer(oldContainer); newSplitter->registerContainer(container); newSplitter->addWidget(oldContainer); newSplitter->addWidget(container); newSplitter->setOrientation(containerOrientation); newSplitter->updateSizes(); newSplitter->show(); splitter->insertWidget(oldContainerIndex, newSplitter); } } void ViewSplitter::containerEmpty(TabbedViewContainer * myContainer) { _containers.removeAll(myContainer); if (count() == 0) { emit empty(this); } int children = 0; foreach (auto container, _containers) { children += container->count(); } if (children == 0) { emit allContainersEmpty(); } // This container is no more, try to find another container to focus. ViewSplitter *currentSplitter = activeSplitter(); while(qobject_cast(currentSplitter->parent())) { currentSplitter = qobject_cast(currentSplitter->parent()); } for(auto tabWidget : currentSplitter->findChildren()) { if (tabWidget != myContainer && tabWidget->count()) { tabWidget->setCurrentIndex(0); } } } void ViewSplitter::activateNextContainer() { TabbedViewContainer *active = activeContainer(); int index = _containers.indexOf(active); if (index == -1) { return; } if (index == _containers.count() - 1) { index = 0; } else { index++; } setActiveContainer(_containers.at(index)); } void ViewSplitter::activatePreviousContainer() { TabbedViewContainer *active = activeContainer(); int index = _containers.indexOf(active); if (index == 0) { index = _containers.count() - 1; } else { index--; } setActiveContainer(_containers.at(index)); } void ViewSplitter::setActiveContainer(TabbedViewContainer *container) { QWidget *activeView = container->currentWidget(); if (activeView != nullptr) { activeView->setFocus(Qt::OtherFocusReason); } } TabbedViewContainer *ViewSplitter::activeContainer() const { if (QWidget *focusW = focusWidget()) { TabbedViewContainer *focusContainer = nullptr; while (focusW != nullptr) { foreach (TabbedViewContainer *container, _containers) { if (container == focusW) { focusContainer = container; break; } } focusW = focusW->parentWidget(); } if (focusContainer != nullptr) { return focusContainer; } } QList splitters = findChildren(); if (!splitters.isEmpty()) { return splitters.last()->activeContainer(); } else { if (!_containers.isEmpty()) { return _containers.last(); } else { return nullptr; } } } diff --git a/src/autotests/CharacterColorTest.cpp b/src/autotests/CharacterColorTest.cpp index f136e58f..5c2600ac 100644 --- a/src/autotests/CharacterColorTest.cpp +++ b/src/autotests/CharacterColorTest.cpp @@ -1,212 +1,212 @@ /* Copyright 2008 by Robert Knight This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ // Own #include "CharacterColorTest.h" // Qt #include #include // KDE #include using namespace Konsole; const ColorEntry CharacterColorTest::DefaultColorTable[TABLE_COLORS] = { ColorEntry(0x00, 0x00, 0x00), // Dfore ColorEntry(0xFF, 0xFF, 0xFF), // Dback ColorEntry(0x00, 0x00, 0x00), // Black ColorEntry(0xB2, 0x18, 0x18), // Red ColorEntry(0x18, 0xB2, 0x18), // Green ColorEntry(0xB2, 0x68, 0x18), // Yellow ColorEntry(0x18, 0x18, 0xB2), // Blue ColorEntry(0xB2, 0x18, 0xB2), // Magenta ColorEntry(0x18, 0xB2, 0xB2), // Cyan ColorEntry(0xB2, 0xB2, 0xB2), // White // intensive versions ColorEntry(0x00, 0x00, 0x00), ColorEntry(0xFF, 0xFF, 0xFF), ColorEntry(0x68, 0x68, 0x68), ColorEntry(0xFF, 0x54, 0x54), ColorEntry(0x54, 0xFF, 0x54), ColorEntry(0xFF, 0xFF, 0x54), ColorEntry(0x54, 0x54, 0xFF), ColorEntry(0xFF, 0x54, 0xFF), ColorEntry(0x54, 0xFF, 0xFF), ColorEntry(0xFF, 0xFF, 0xFF), // Here are faint intensities, which may not be good. // faint versions ColorEntry(0x00, 0x00, 0x00), ColorEntry(0xFF, 0xFF, 0xFF), ColorEntry(0x00, 0x00, 0x00), ColorEntry(0x65, 0x00, 0x00), ColorEntry(0x00, 0x65, 0x00), ColorEntry(0x65, 0x5E, 0x00), ColorEntry(0x00, 0x00, 0x65), ColorEntry(0x65, 0x00, 0x65), ColorEntry(0x00, 0x65, 0x65), ColorEntry(0x65, 0x65, 0x65) }; void CharacterColorTest::init() { } void CharacterColorTest::cleanup() { } void CharacterColorTest::testColorEntry() { ColorEntry black = ColorEntry(0x00, 0x00, 0x00); ColorEntry white = ColorEntry(0xFF, 0xFF, 0xFF); ColorEntry red = ColorEntry(0xB2, 0x18, 0x18); ColorEntry green = ColorEntry(0x18, 0xB2, 0x18); // Test operator== operator!= QCOMPARE(black == white, false); QCOMPARE(black != white, true); QCOMPARE(red == green, false); QCOMPARE(red != green, true); QCOMPARE(red == green, false); QCOMPARE(red != green, true); // Test operator= ColorEntry tmpColorEntry; tmpColorEntry = red; QCOMPARE(tmpColorEntry == red, true); QCOMPARE(red == tmpColorEntry, true); // Test ColorEntry() ColorEntry defaultColorEntry = ColorEntry(); QCOMPARE(defaultColorEntry != green, true); QCOMPARE(defaultColorEntry != black, true); QCOMPARE(defaultColorEntry.isValid(), false); } void CharacterColorTest::testDummyConstructor() { CharacterColor charColor; QCOMPARE(charColor.isValid(), false); } void CharacterColorTest::testColorSpaceDefault_data() { QTest::addColumn("colorValue"); QTest::addColumn("expected"); QTest::newRow("color 0") << 0 << DefaultColorTable[0]; QTest::newRow("color 1") << 1 << DefaultColorTable[1]; } void CharacterColorTest::testColorSpaceDefault() { QFETCH(int, colorValue); QFETCH(QColor, expected); CharacterColor charColor(COLOR_SPACE_DEFAULT, colorValue); const QColor result = charColor.color(DefaultColorTable); QCOMPARE(result, expected); } void CharacterColorTest::testColorSpaceSystem_data() { QTest::addColumn("colorValue"); QTest::addColumn("expected"); QTest::newRow("color 0") << 0 << DefaultColorTable[2 + 0]; QTest::newRow("color 1") << 1 << DefaultColorTable[2 + 1]; QTest::newRow("color 7") << 7 << DefaultColorTable[2 + 7]; } void CharacterColorTest::testColorSpaceSystem() { QFETCH(int, colorValue); QFETCH(QColor, expected); CharacterColor charColor(COLOR_SPACE_SYSTEM, colorValue); const QColor result = charColor.color(DefaultColorTable); QCOMPARE(result, expected); } void CharacterColorTest::testColorSpaceRGB_data() { QTest::addColumn("colorValue"); QTest::addColumn("expected"); // Pick colors to test or test all if needed for (const int i : {0, 1, 64, 127, 128, 215, 255}) { - const QString name = QString::fromLatin1("color %1").arg(i); + const QString name = QStringLiteral("color %1").arg(i); QTest::newRow(qPrintable(name)) << i << QColor(i >> 16, i >> 8, i); } } void CharacterColorTest::testColorSpaceRGB() { QFETCH(int, colorValue); QFETCH(QColor, expected); CharacterColor charColor(COLOR_SPACE_RGB, colorValue); const QColor result = charColor.color(DefaultColorTable); QCOMPARE(result, expected); } void CharacterColorTest::testColor256_data() { QTest::addColumn("colorValue"); QTest::addColumn("expected"); // This might be overkill for (int i = 0; i < 8; ++i) { - const QString name = QString::fromLatin1("color256 color %1").arg(i); + const QString name = QStringLiteral("color256 color %1").arg(i); QTest::newRow(qPrintable(name)) << i << DefaultColorTable[i + 2]; } for (int i = 8; i < 16; ++i) { - const QString name = QString::fromLatin1("color256 color %1").arg(i); + const QString name = QStringLiteral("color256 color %1").arg(i); QTest::newRow(qPrintable(name)) << i << DefaultColorTable[i + 2 + 10 - 8]; } for (int i = 16; i < 232; ++i) { - const QString name = QString::fromLatin1("color256 color %1").arg(i); + const QString name = QStringLiteral("color256 color %1").arg(i); const auto u = i - 16; const auto color = QColor(((u / 36) % 6) ? (40 * ((u / 36) % 6) + 55) : 0, ((u / 6) % 6) ? (40 * ((u / 6) % 6) + 55) : 0, ((u / 1) % 6) ? (40 * ((u / 1) % 6) + 55) : 0); QTest::newRow(qPrintable(name)) << i << color; } for (int i = 232; i < 256; ++i) { - const QString name = QString::fromLatin1("color256 color %1").arg(i); + const QString name = QStringLiteral("color256 color %1").arg(i); const auto gray = (i - 232) * 10 + 8; QTest::newRow(qPrintable(name)) << i << QColor(gray, gray, gray); } } void CharacterColorTest::testColor256() { QFETCH(int, colorValue); QFETCH(QColor, expected); const QColor result = color256(colorValue, DefaultColorTable); QCOMPARE(result, expected); } QTEST_GUILESS_MAIN(CharacterColorTest)