summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/corelib/io/qfsfileengine.cpp2
-rw-r--r--src/corelib/io/qfsfileengine_win.cpp28
-rw-r--r--src/corelib/plugin/qlibrary.cpp140
-rw-r--r--src/gui/kernel/qmacdefines_mac.h12
-rw-r--r--src/gui/kernel/qpalette.cpp2
-rw-r--r--tests/auto/declarative/qdeclarativedom/data/importlib/sublib/qmldir2
-rw-r--r--tests/auto/networkselftest/tst_networkselftest.cpp4
-rw-r--r--tests/auto/qdir/tst_qdir.cpp5
-rw-r--r--tests/auto/qfileinfo/tst_qfileinfo.cpp125
-rw-r--r--tests/benchmarks/corelib/io/qfileinfo/main.cpp44
-rw-r--r--tests/shared/filesystem.h62
-rw-r--r--tools/assistant/tools/assistant/assistant.pro17
-rw-r--r--tools/assistant/tools/assistant/assistant_images.qrc6
-rw-r--r--tools/assistant/tools/assistant/centralwidget.cpp690
-rw-r--r--tools/assistant/tools/assistant/centralwidget.h53
-rw-r--r--tools/assistant/tools/assistant/contentwindow.cpp5
-rw-r--r--tools/assistant/tools/assistant/globalactions.cpp163
-rw-r--r--tools/assistant/tools/assistant/globalactions.h91
-rw-r--r--tools/assistant/tools/assistant/helpenginewrapper.cpp12
-rw-r--r--tools/assistant/tools/assistant/helpenginewrapper.h3
-rw-r--r--tools/assistant/tools/assistant/helpviewer_qtb.cpp15
-rw-r--r--tools/assistant/tools/assistant/helpviewer_qtb.h7
-rw-r--r--tools/assistant/tools/assistant/helpviewer_qwv.cpp35
-rw-r--r--tools/assistant/tools/assistant/helpviewer_qwv.h5
-rw-r--r--tools/assistant/tools/assistant/images/closebutton.pngbin0 -> 288 bytes
-rw-r--r--tools/assistant/tools/assistant/images/darkclosebutton.pngbin0 -> 319 bytes
-rw-r--r--tools/assistant/tools/assistant/indexwindow.cpp3
-rw-r--r--tools/assistant/tools/assistant/mainwindow.cpp309
-rw-r--r--tools/assistant/tools/assistant/mainwindow.h27
-rw-r--r--tools/assistant/tools/assistant/openpagesmanager.cpp310
-rw-r--r--tools/assistant/tools/assistant/openpagesmanager.h104
-rw-r--r--tools/assistant/tools/assistant/openpagesmodel.cpp123
-rw-r--r--tools/assistant/tools/assistant/openpagesmodel.h76
-rw-r--r--tools/assistant/tools/assistant/openpageswidget.cpp196
-rw-r--r--tools/assistant/tools/assistant/openpageswidget.h88
-rw-r--r--tools/assistant/tools/assistant/preferencesdialog.cpp15
-rw-r--r--tools/assistant/tools/assistant/preferencesdialog.h1
-rw-r--r--tools/assistant/tools/assistant/remotecontrol.cpp10
38 files changed, 1809 insertions, 981 deletions
diff --git a/src/corelib/io/qfsfileengine.cpp b/src/corelib/io/qfsfileengine.cpp
index a1ffb81..3cf08a7 100644
--- a/src/corelib/io/qfsfileengine.cpp
+++ b/src/corelib/io/qfsfileengine.cpp
@@ -208,6 +208,8 @@ QString QFSFileEnginePrivate::canonicalized(const QString &path)
fi.setFile(prefix);
if (fi.isSymLink()) {
QString target = fi.symLinkTarget();
+ if(QFileInfo(target).isRelative())
+ target = fi.absolutePath() + slash + target;
if (separatorPos != -1) {
if (fi.isDir() && !target.endsWith(slash))
target.append(slash);
diff --git a/src/corelib/io/qfsfileengine_win.cpp b/src/corelib/io/qfsfileengine_win.cpp
index ec49f1a..cc9b8c7 100644
--- a/src/corelib/io/qfsfileengine_win.cpp
+++ b/src/corelib/io/qfsfileengine_win.cpp
@@ -154,6 +154,8 @@ static TRUSTEE_W worldTrusteeW;
typedef BOOL (WINAPI *PtrGetUserProfileDirectoryW)(HANDLE, LPWSTR, LPDWORD);
static PtrGetUserProfileDirectoryW ptrGetUserProfileDirectoryW = 0;
+typedef BOOL (WINAPI *PtrGetVolumePathNamesForVolumeNameW)(LPCWSTR,LPWSTR,DWORD,PDWORD);
+static PtrGetVolumePathNamesForVolumeNameW ptrGetVolumePathNamesForVolumeNameW = 0;
QT_END_INCLUDE_NAMESPACE
@@ -212,6 +214,9 @@ void QFSFileEnginePrivate::resolveLibs()
HINSTANCE userenvHnd = LoadLibrary(L"userenv");
if (userenvHnd)
ptrGetUserProfileDirectoryW = (PtrGetUserProfileDirectoryW)GetProcAddress(userenvHnd, "GetUserProfileDirectoryW");
+ HINSTANCE kernel32 = LoadLibrary(L"kernel32");
+ if(kernel32)
+ ptrGetVolumePathNamesForVolumeNameW = (PtrGetVolumePathNamesForVolumeNameW)GetProcAddress(kernel32, "GetVolumePathNamesForVolumeNameW");
#endif
}
}
@@ -1277,7 +1282,12 @@ static QString readSymLink(const QString &link)
REPARSE_DATA_BUFFER *rdb = (REPARSE_DATA_BUFFER*)qMalloc(bufsize);
DWORD retsize = 0;
if (::DeviceIoControl(handle, FSCTL_GET_REPARSE_POINT, 0, 0, rdb, bufsize, &retsize, 0)) {
- if (rdb->ReparseTag == IO_REPARSE_TAG_SYMLINK) {
+ if (rdb->ReparseTag == IO_REPARSE_TAG_MOUNT_POINT) {
+ int length = rdb->MountPointReparseBuffer.SubstituteNameLength / sizeof(wchar_t);
+ int offset = rdb->MountPointReparseBuffer.SubstituteNameOffset / sizeof(wchar_t);
+ const wchar_t* PathBuffer = &rdb->MountPointReparseBuffer.PathBuffer[offset];
+ result = QString::fromWCharArray(PathBuffer, length);
+ } else if (rdb->ReparseTag == IO_REPARSE_TAG_SYMLINK) {
int length = rdb->SymbolicLinkReparseBuffer.SubstituteNameLength / sizeof(wchar_t);
int offset = rdb->SymbolicLinkReparseBuffer.SubstituteNameOffset / sizeof(wchar_t);
const wchar_t* PathBuffer = &rdb->SymbolicLinkReparseBuffer.PathBuffer[offset];
@@ -1289,6 +1299,20 @@ static QString readSymLink(const QString &link)
}
qFree(rdb);
CloseHandle(handle);
+
+#if !defined(QT_NO_LIBRARY)
+ QFSFileEnginePrivate::resolveLibs();
+ if (ptrGetVolumePathNamesForVolumeNameW) {
+ QRegExp matchVolName(QLatin1String("^Volume\\{([a-z]|[0-9]|-)+\\}\\\\"), Qt::CaseInsensitive);
+ if(matchVolName.indexIn(result) == 0) {
+ DWORD len;
+ wchar_t buffer[MAX_PATH];
+ QString volumeName = result.mid(0, matchVolName.matchedLength()).prepend(QLatin1String("\\\\?\\"));
+ if(ptrGetVolumePathNamesForVolumeNameW((wchar_t*)volumeName.utf16(), buffer, MAX_PATH, &len) != 0)
+ result.replace(0,matchVolName.matchedLength(), QString::fromWCharArray(buffer));
+ }
+ }
+#endif
}
#else
Q_UNUSED(link);
@@ -1540,7 +1564,7 @@ bool QFSFileEnginePrivate::isSymlink() const
if (hFind != INVALID_HANDLE_VALUE) {
::FindClose(hFind);
if ((findData.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT)
- && findData.dwReserved0 == IO_REPARSE_TAG_SYMLINK) {
+ && (findData.dwReserved0 == IO_REPARSE_TAG_SYMLINK || findData.dwReserved0 == IO_REPARSE_TAG_MOUNT_POINT)) {
is_link = true;
}
}
diff --git a/src/corelib/plugin/qlibrary.cpp b/src/corelib/plugin/qlibrary.cpp
index 0f99948..2ed113d 100644
--- a/src/corelib/plugin/qlibrary.cpp
+++ b/src/corelib/plugin/qlibrary.cpp
@@ -609,6 +609,46 @@ bool QLibrary::isLibrary(const QString &fileName)
}
+#if defined (Q_OS_WIN) && defined(_MSC_VER) && _MSC_VER >= 1400 && !defined(Q_CC_INTEL)
+#define QT_USE_MS_STD_EXCEPTION 1
+const char* qt_try_versioninfo(void *pfn, bool *exceptionThrown)
+{
+ *exceptionThrown = false;
+ const char *szData = 0;
+ typedef const char * (*VerificationFunction)();
+ VerificationFunction func = reinterpret_cast<VerificationFunction>(pfn);
+ __try {
+ if(func)
+ szData = func();
+ } __except(EXCEPTION_EXECUTE_HANDLER) {
+ *exceptionThrown = true;
+ }
+ return szData;
+}
+#endif
+
+#ifdef Q_CC_BOR
+typedef const char * __stdcall (*QtPluginQueryVerificationDataFunction)();
+#else
+typedef const char * (*QtPluginQueryVerificationDataFunction)();
+#endif
+
+bool qt_get_verificationdata(QtPluginQueryVerificationDataFunction pfn, uint *qt_version, bool *debug, QByteArray *key, bool *exceptionThrown)
+{
+ *exceptionThrown = false;
+ const char *szData = 0;
+ if (!pfn)
+ return false;
+#ifdef QT_USE_MS_STD_EXCEPTION
+ szData = qt_try_versioninfo((void *)pfn, exceptionThrown);
+ if (*exceptionThrown)
+ return false;
+#else
+ szData = pfn();
+#endif
+ return qt_parse_pattern(szData, qt_version, debug, key);
+}
+
bool QLibraryPrivate::isPlugin(QSettings *settings)
{
errorString.clear();
@@ -684,70 +724,82 @@ bool QLibraryPrivate::isPlugin(QSettings *settings)
} else
#endif
{
- bool temporary_load = false;
+ bool retryLoadLibrary = false; // Only used on Windows with MS compiler.(false in other cases)
+ do {
+ bool temporary_load = false;
#ifdef Q_OS_WIN
- HMODULE hTempModule = 0;
+ HMODULE hTempModule = 0;
#endif
- if (!pHnd) {
+ if (!pHnd) {
#ifdef Q_OS_WIN
- //avoid 'Bad Image' message box
- UINT oldmode = SetErrorMode(SEM_FAILCRITICALERRORS|SEM_NOOPENFILEERRORBOX);
- hTempModule = ::LoadLibraryEx((wchar_t*)QDir::toNativeSeparators(fileName).utf16(), 0, DONT_RESOLVE_DLL_REFERENCES);
- SetErrorMode(oldmode);
+ DWORD dwFlags = (retryLoadLibrary) ? 0: DONT_RESOLVE_DLL_REFERENCES;
+ //avoid 'Bad Image' message box
+ UINT oldmode = SetErrorMode(SEM_FAILCRITICALERRORS|SEM_NOOPENFILEERRORBOX);
+ hTempModule = ::LoadLibraryEx((wchar_t*)QDir::toNativeSeparators(fileName).utf16(), 0, dwFlags);
+ SetErrorMode(oldmode);
#else
# if defined(Q_OS_SYMBIAN)
- //Guard against accidentally trying to load non-plugin libraries by making sure the stub exists
- if (fileinfo.exists())
+ //Guard against accidentally trying to load non-plugin libraries by making sure the stub exists
+ if (fileinfo.exists())
# endif
- temporary_load = load_sys();
+ temporary_load = load_sys();
#endif
- }
-# ifdef Q_CC_BOR
- typedef const char * __stdcall (*QtPluginQueryVerificationDataFunction)();
-# else
- typedef const char * (*QtPluginQueryVerificationDataFunction)();
-# endif
+ }
#ifdef Q_OS_WIN
- QtPluginQueryVerificationDataFunction qtPluginQueryVerificationDataFunction = hTempModule
- ? (QtPluginQueryVerificationDataFunction)
+ QtPluginQueryVerificationDataFunction qtPluginQueryVerificationDataFunction = hTempModule ? (QtPluginQueryVerificationDataFunction)
#ifdef Q_OS_WINCE
- ::GetProcAddress(hTempModule, L"qt_plugin_query_verification_data")
+ ::GetProcAddress(hTempModule, L"qt_plugin_query_verification_data")
#else
- ::GetProcAddress(hTempModule, "qt_plugin_query_verification_data")
+ ::GetProcAddress(hTempModule, "qt_plugin_query_verification_data")
#endif
: (QtPluginQueryVerificationDataFunction) resolve("qt_plugin_query_verification_data");
#else
- QtPluginQueryVerificationDataFunction qtPluginQueryVerificationDataFunction = NULL;
+ QtPluginQueryVerificationDataFunction qtPluginQueryVerificationDataFunction = NULL;
# if defined(Q_OS_SYMBIAN)
- if (temporary_load) {
- qtPluginQueryVerificationDataFunction = (QtPluginQueryVerificationDataFunction) resolve("qt_plugin_query_verification_data");
- // If resolving with function name failed (i.e. not STDDLL), try resolving using known ordinal
- if (!qtPluginQueryVerificationDataFunction)
- qtPluginQueryVerificationDataFunction = (QtPluginQueryVerificationDataFunction) resolve("1");
- }
+ if (temporary_load) {
+ qtPluginQueryVerificationDataFunction = (QtPluginQueryVerificationDataFunction) resolve("qt_plugin_query_verification_data");
+ // If resolving with function name failed (i.e. not STDDLL), try resolving using known ordinal
+ if (!qtPluginQueryVerificationDataFunction)
+ qtPluginQueryVerificationDataFunction = (QtPluginQueryVerificationDataFunction) resolve("1");
+ }
# else
- qtPluginQueryVerificationDataFunction = (QtPluginQueryVerificationDataFunction) resolve("qt_plugin_query_verification_data");
+ qtPluginQueryVerificationDataFunction = (QtPluginQueryVerificationDataFunction) resolve("qt_plugin_query_verification_data");
# endif
#endif
-
- if (!qtPluginQueryVerificationDataFunction
- || !qt_parse_pattern(qtPluginQueryVerificationDataFunction(), &qt_version, &debug, &key)) {
- qt_version = 0;
- key = "unknown";
- if (temporary_load)
- unload_sys();
- } else {
- success = true;
- }
-#ifdef Q_OS_WIN
- if (hTempModule) {
- BOOL ok = ::FreeLibrary(hTempModule);
- if (ok) {
- hTempModule = 0;
+ bool exceptionThrown = false;
+ bool ret = qt_get_verificationdata(qtPluginQueryVerificationDataFunction,
+ &qt_version, &debug, &key, &exceptionThrown);
+ if (!exceptionThrown) {
+ if (!ret) {
+ qt_version = 0;
+ key = "unknown";
+ if (temporary_load)
+ unload_sys();
+ } else {
+ success = true;
+ }
+ retryLoadLibrary = false;
+ }
+#ifdef QT_USE_MS_STD_EXCEPTION
+ else {
+ // An exception was thrown when calling qt_plugin_query_verification_data().
+ // This usually happens when plugin is compiled with the /clr compiler flag,
+ // & will only work if the dependencies are loaded & DLLMain() is called.
+ // LoadLibrary() will do this, try once with this & if it fails dont load.
+ retryLoadLibrary = !retryLoadLibrary;
}
+#endif
+#ifdef Q_OS_WIN
+ if (hTempModule) {
+ BOOL ok = ::FreeLibrary(hTempModule);
+ if (ok) {
+ hTempModule = 0;
+ }
- }
+ }
#endif
+ } while(retryLoadLibrary); // Will be 'false' in all cases other than when an
+ // exception is thrown(will happen only when using a MS compiler)
}
// Qt 4.5 compatibility: stl doesn't affect binary compatibility
diff --git a/src/gui/kernel/qmacdefines_mac.h b/src/gui/kernel/qmacdefines_mac.h
index d767470..d190d23 100644
--- a/src/gui/kernel/qmacdefines_mac.h
+++ b/src/gui/kernel/qmacdefines_mac.h
@@ -94,12 +94,6 @@ Yes, it is an informative comment ;-)
#include <QtCore/qglobal.h>
-#undef OLD_DEBUG
-#ifdef DEBUG
-# define OLD_DEBUG DEBUG
-# undef DEBUG
-#endif
-#define DEBUG 0
#ifdef qDebug
# define old_qDebug qDebug
# undef qDebug
@@ -179,12 +173,6 @@ typedef AERecord AppleEvent;
#undef check
#endif
-#undef DEBUG
-#ifdef OLD_DEBUG
-# define DEBUG OLD_DEBUG
-# undef OLD_DEBUG
-#endif
-
#ifdef old_qDebug
# undef qDebug
# define qDebug QT_NO_QDEBUG_MACRO
diff --git a/src/gui/kernel/qpalette.cpp b/src/gui/kernel/qpalette.cpp
index 6e8c90e..98e8f66 100644
--- a/src/gui/kernel/qpalette.cpp
+++ b/src/gui/kernel/qpalette.cpp
@@ -795,7 +795,7 @@ const QBrush &QPalette::brush(ColorGroup gr, ColorRole cr) const
/*!
\fn void QPalette::setColor(ColorGroup group, ColorRole role, const QColor &color)
- Sets the brush in the specified color \a group, used for the given
+ Sets the color in the specified color \a group, used for the given
color \a role, to the specified solid \a color.
\sa setBrush() color() ColorRole
diff --git a/tests/auto/declarative/qdeclarativedom/data/importlib/sublib/qmldir b/tests/auto/declarative/qdeclarativedom/data/importlib/sublib/qmldir
deleted file mode 100644
index 98d6b74..0000000
--- a/tests/auto/declarative/qdeclarativedom/data/importlib/sublib/qmldir
+++ /dev/null
@@ -1,2 +0,0 @@
-Foo 1.1 Foo.qml
-Foo 1.0 Foo.qml
diff --git a/tests/auto/networkselftest/tst_networkselftest.cpp b/tests/auto/networkselftest/tst_networkselftest.cpp
index d25fcb6..ecbc08c 100644
--- a/tests/auto/networkselftest/tst_networkselftest.cpp
+++ b/tests/auto/networkselftest/tst_networkselftest.cpp
@@ -965,11 +965,11 @@ void tst_NetworkSelfTest::smbServer()
QVERIFY2(f, qt_error_string().toLocal8Bit());
char buf[128];
- ssize_t ret = fread(buf, sizeof buf, 1, f);
+ size_t ret = fread(buf, sizeof buf, 1, f);
fclose(f);
QCOMPARE(ret, strlen(contents));
- QVERIFY(memcmp(ret, contents, strlen(contents)) == 0);
+ QVERIFY(memcmp(buf, contents, strlen(contents)) == 0);
#else
// try to use Samba
QString progname = "smbclient";
diff --git a/tests/auto/qdir/tst_qdir.cpp b/tests/auto/qdir/tst_qdir.cpp
index c8c835f..71469bb 100644
--- a/tests/auto/qdir/tst_qdir.cpp
+++ b/tests/auto/qdir/tst_qdir.cpp
@@ -49,6 +49,11 @@
#include <qregexp.h>
#include <qstringlist.h>
#include "../network-settings.h"
+
+#if defined(Q_OS_WIN)
+#define _WIN32_WINNT 0x500
+#endif
+
#include "../../shared/filesystem.h"
#if defined(Q_OS_SYMBIAN)
diff --git a/tests/auto/qfileinfo/tst_qfileinfo.cpp b/tests/auto/qfileinfo/tst_qfileinfo.cpp
index 403c5f9..ca8c1c9 100644
--- a/tests/auto/qfileinfo/tst_qfileinfo.cpp
+++ b/tests/auto/qfileinfo/tst_qfileinfo.cpp
@@ -55,7 +55,9 @@
#include <sys/stat.h>
#endif
#ifdef Q_OS_WIN
+#define _WIN32_WINNT 0x500
#include <qt_windows.h>
+#include <qlibrary.h>
#endif
#include <qplatformdefs.h>
#include <qdebug.h>
@@ -65,6 +67,7 @@
#endif
#include "../network-settings.h"
#include <private/qfileinfo_p.h>
+#include "../../shared/filesystem.h"
#if defined(Q_OS_SYMBIAN)
# define SRCDIR ""
@@ -161,6 +164,8 @@ private slots:
void refresh();
#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE)
+ void ntfsJunctionPointsAndSymlinks_data();
+ void ntfsJunctionPointsAndSymlinks();
void brokenShortcut();
#endif
@@ -194,8 +199,15 @@ tst_QFileInfo::~tst_QFileInfo()
#if defined(Q_OS_UNIX) && !defined(Q_OS_SYMBIAN)
QDir().rmdir("./.hidden-directory");
#endif
-#ifdef Q_OS_WIN
+#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE)
QDir().rmdir("./hidden-directory");
+ QDir().rmdir("abs_symlink");
+ QDir().rmdir("rel_symlink");
+ QDir().rmdir("junction_pwd");
+ QDir().rmdir("junction_root");
+ QDir().rmdir("mountpoint");
+ QFile::remove("abs_symlink.cpp");
+ QFile::remove("rel_symlink.cpp");
#endif
}
@@ -1082,7 +1094,7 @@ void tst_QFileInfo::isHidden_data()
#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE)
QVERIFY(QDir("./hidden-directory").exists() || QDir().mkdir("./hidden-directory"));
- QVERIFY(SetFileAttributesW(QString("./hidden-directory").utf16(),FILE_ATTRIBUTE_HIDDEN));
+ QVERIFY(SetFileAttributesW((wchar_t*)QString("./hidden-directory").utf16(),FILE_ATTRIBUTE_HIDDEN));
QTest::newRow("C:/path/to/hidden-directory") << QDir::currentPath() + QString::fromLatin1("/hidden-directory") << true;
QTest::newRow("C:/path/to/hidden-directory/.") << QDir::currentPath() + QString::fromLatin1("/hidden-directory/.") << true;
#endif
@@ -1236,6 +1248,115 @@ void tst_QFileInfo::refresh()
}
#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE)
+void tst_QFileInfo::ntfsJunctionPointsAndSymlinks_data()
+{
+ QTest::addColumn<QString>("path");
+ QTest::addColumn<bool>("isSymLink");
+ QTest::addColumn<QString>("linkTarget");
+ QTest::addColumn<QString>("canonicalFilePath");
+
+ QDir pwd;
+ pwd.mkdir("target");
+
+ QLibrary kernel32("kernel32");
+ typedef BOOLEAN (WINAPI *PtrCreateSymbolicLink)(LPCWSTR, LPCWSTR, DWORD);
+ PtrCreateSymbolicLink createSymbolicLinkW = 0;
+ createSymbolicLinkW = (PtrCreateSymbolicLink) kernel32.resolve("CreateSymbolicLinkW");
+ if (!createSymbolicLinkW) {
+ //we need at least one data set for the test not to fail when skipping _data function
+ QDir target("target");
+ QTest::newRow("dummy") << target.path() << false << "" << target.canonicalPath();
+ QSKIP("symbolic links not supported by operating system",SkipSingle);
+ }
+ {
+ //Directory symlinks
+ QDir target("target");
+ QVERIFY(target.exists());
+
+ QString absTarget = QDir::toNativeSeparators(target.absolutePath());
+ QString absSymlink = QDir::toNativeSeparators(pwd.absolutePath()).append("\\abs_symlink");
+ QString relTarget = "target";
+ QString relSymlink = "rel_symlink";
+ QString fileInTarget(absTarget);
+ fileInTarget.append("\\file");
+ QString fileInSymlink(absSymlink);
+ fileInSymlink.append("\\file");
+ QFile file(fileInTarget);
+ file.open(QIODevice::ReadWrite);
+ file.close();
+
+ QVERIFY(pwd.exists("abs_symlink") || createSymbolicLinkW((wchar_t*)absSymlink.utf16(),(wchar_t*)absTarget.utf16(),0x1));
+ QVERIFY(pwd.exists(relSymlink) || createSymbolicLinkW((wchar_t*)relSymlink.utf16(),(wchar_t*)relTarget.utf16(),0x1));
+ QVERIFY(file.exists());
+
+ QTest::newRow("absolute dir symlink") << absSymlink << true << QDir::fromNativeSeparators(absTarget) << target.canonicalPath();
+ QTest::newRow("relative dir symlink") << relSymlink << true << QDir::fromNativeSeparators(relTarget) << target.canonicalPath();
+ QTest::newRow("file in symlink dir") << fileInSymlink << false << "" << target.canonicalPath().append("/file");
+ }
+ {
+ //File symlinks
+ QFileInfo target(SRCDIR "tst_qfileinfo.cpp");
+ QString absTarget = QDir::toNativeSeparators(target.absoluteFilePath());
+ QString absSymlink = QDir::toNativeSeparators(pwd.absolutePath()).append("\\abs_symlink.cpp");
+ QString relTarget = QDir::toNativeSeparators(pwd.relativeFilePath(target.absoluteFilePath()));
+ QString relSymlink = "rel_symlink.cpp";
+ QVERIFY(pwd.exists("abs_symlink.cpp") || createSymbolicLinkW((wchar_t*)absSymlink.utf16(),(wchar_t*)absTarget.utf16(),0x0));
+ QVERIFY(pwd.exists(relSymlink) || createSymbolicLinkW((wchar_t*)relSymlink.utf16(),(wchar_t*)relTarget.utf16(),0x0));
+
+ QTest::newRow("absolute file symlink") << absSymlink << true << QDir::fromNativeSeparators(absTarget) << target.canonicalFilePath();
+ QTest::newRow("relative file symlink") << relSymlink << true << QDir::fromNativeSeparators(relTarget) << target.canonicalFilePath();
+ }
+
+ //Junctions
+ QString target = "target";
+ QString junction = "junction_pwd";
+ FileSystem::createNtfsJunction(target, junction);
+ QFileInfo targetInfo(target);
+ QTest::newRow("junction_pwd") << junction << true << targetInfo.absoluteFilePath() << targetInfo.canonicalFilePath();
+
+ QFileInfo fileInJunction(targetInfo.absoluteFilePath().append("/file"));
+ QFile file(fileInJunction.absoluteFilePath());
+ file.open(QIODevice::ReadWrite);
+ file.close();
+ QVERIFY(file.exists());
+ QTest::newRow("file in junction") << fileInJunction.absoluteFilePath() << false << "" << fileInJunction.canonicalFilePath();
+
+ target = QDir::rootPath();
+ junction = "junction_root";
+ FileSystem::createNtfsJunction(target, junction);
+ targetInfo.setFile(target);
+ QTest::newRow("junction_root") << junction << true << targetInfo.absoluteFilePath() << targetInfo.canonicalFilePath();
+
+ //Mountpoint
+ typedef BOOLEAN (WINAPI *PtrGetVolumeNameForVolumeMountPointW)(LPCWSTR, LPWSTR, DWORD);
+ PtrGetVolumeNameForVolumeMountPointW getVolumeNameForVolumeMountPointW = 0;
+ getVolumeNameForVolumeMountPointW = (PtrGetVolumeNameForVolumeMountPointW) kernel32.resolve("GetVolumeNameForVolumeMountPointW");
+ if(getVolumeNameForVolumeMountPointW)
+ {
+ wchar_t buffer[MAX_PATH];
+ QString rootPath = QDir::toNativeSeparators(QDir::rootPath());
+ QVERIFY(getVolumeNameForVolumeMountPointW((wchar_t*)rootPath.utf16(), buffer, MAX_PATH));
+ QString rootVolume = QString::fromWCharArray(buffer);
+ junction = "mountpoint";
+ rootVolume.replace("\\\\?\\","\\??\\");
+ FileSystem::createNtfsJunction(rootVolume, junction);
+ QTest::newRow("mountpoint") << junction << true << QDir::fromNativeSeparators(rootPath) << QDir::rootPath();
+ }
+}
+
+void tst_QFileInfo::ntfsJunctionPointsAndSymlinks()
+{
+ QFETCH(QString, path);
+ QFETCH(bool, isSymLink);
+ QFETCH(QString, linkTarget);
+ QFETCH(QString, canonicalFilePath);
+
+ QFileInfo fi(path);
+ QCOMPARE(fi.isSymLink(), isSymLink);
+ QCOMPARE(fi.symLinkTarget(), linkTarget);
+ QCOMPARE(fi.canonicalFilePath(), canonicalFilePath);
+}
+
void tst_QFileInfo::brokenShortcut()
{
QString linkName("borkenlink.lnk");
diff --git a/tests/benchmarks/corelib/io/qfileinfo/main.cpp b/tests/benchmarks/corelib/io/qfileinfo/main.cpp
index 025787f..b272bda 100644
--- a/tests/benchmarks/corelib/io/qfileinfo/main.cpp
+++ b/tests/benchmarks/corelib/io/qfileinfo/main.cpp
@@ -43,15 +43,20 @@
#include <QtTest/QtTest>
#include <QtCore/QCoreApplication>
#include <QtCore/QFileInfo>
+#include <QtCore/QFile>
#include "private/qfsfileengine_p.h"
+#include "../../../../shared/filesystem.h"
class qfileinfo : public QObject
{
Q_OBJECT
private slots:
void canonicalFileNamePerformance();
-
+#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE)
+ void symLinkTargetPerformanceLNK();
+ void symLinkTargetPerformanceMounpoint();
+#endif
void initTestCase();
void cleanupTestCase();
public:
@@ -78,6 +83,43 @@ void qfileinfo::canonicalFileNamePerformance()
}
}
+#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE)
+void qfileinfo::symLinkTargetPerformanceLNK()
+{
+ QVERIFY(QFile::link("file","link.lnk"));
+ QFileInfo info("link.lnk");
+ info.setCaching(false);
+ QVERIFY(info.isSymLink());
+ QString linkTarget;
+ QBENCHMARK {
+ for(int i=0; i<100; i++)
+ linkTarget = info.readLink();
+ }
+ QVERIFY(QFile::remove("link.lnk"));
+}
+
+void qfileinfo::symLinkTargetPerformanceMounpoint()
+{
+ wchar_t buffer[MAX_PATH];
+ QString rootPath = QDir::toNativeSeparators(QDir::rootPath());
+ QVERIFY(GetVolumeNameForVolumeMountPointW(rootPath.utf16(), buffer, MAX_PATH));
+ QString rootVolume = QString::fromWCharArray(buffer);
+ QString mountpoint = "mountpoint";
+ rootVolume.replace("\\\\?\\","\\??\\");
+ FileSystem::createNtfsJunction(rootVolume, mountpoint);
+
+ QFileInfo info(mountpoint);
+ info.setCaching(false);
+ QVERIFY(info.isSymLink());
+ QString linkTarget;
+ QBENCHMARK {
+ for(int i=0; i<100; i++)
+ linkTarget = info.readLink();
+ }
+ QVERIFY(QDir().rmdir(mountpoint));
+}
+#endif
+
QTEST_MAIN(qfileinfo)
#include "main.moc"
diff --git a/tests/shared/filesystem.h b/tests/shared/filesystem.h
index 2d46c0d..079a6dc 100644
--- a/tests/shared/filesystem.h
+++ b/tests/shared/filesystem.h
@@ -48,6 +48,15 @@
#include <QDir>
#include <QFile>
+#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE)
+#include <windows.h>
+#include <winioctl.h>
+#ifndef IO_REPARSE_TAG_MOUNT_POINT
+#define IO_REPARSE_TAG_MOUNT_POINT (0xA0000003L)
+#endif
+#define REPARSE_MOUNTPOINT_HEADER_SIZE 8
+#endif
+
struct FileSystem
{
~FileSystem()
@@ -86,6 +95,59 @@ struct FileSystem
}
return false;
}
+#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE)
+ static void createNtfsJunction(QString target, QString linkName)
+ {
+ typedef struct {
+ DWORD ReparseTag;
+ DWORD ReparseDataLength;
+ WORD Reserved;
+ WORD ReparseTargetLength;
+ WORD ReparseTargetMaximumLength;
+ WORD Reserved1;
+ WCHAR ReparseTarget[1];
+ } REPARSE_MOUNTPOINT_DATA_BUFFER, *PREPARSE_MOUNTPOINT_DATA_BUFFER;
+
+ char reparseBuffer[MAX_PATH*3];
+ HANDLE hFile;
+ DWORD returnedLength;
+ wchar_t fileSystem[MAX_PATH] = L"";
+ PREPARSE_MOUNTPOINT_DATA_BUFFER reparseInfo = (PREPARSE_MOUNTPOINT_DATA_BUFFER) reparseBuffer;
+
+ QFileInfo junctionInfo(linkName);
+ linkName = QDir::toNativeSeparators(junctionInfo.absoluteFilePath());
+
+ GetVolumeInformationW( (wchar_t*)linkName.left(3).utf16(), NULL, 0, NULL, NULL, NULL,
+ fileSystem, sizeof(fileSystem)/sizeof(WCHAR));
+ if(QString().fromWCharArray(fileSystem) != "NTFS")
+ QSKIP("This seems not to be an NTFS volume. Junctions are not allowed.",SkipSingle);
+
+ if (!target.startsWith("\\??\\") && !target.startsWith("\\\\?\\")) {
+ QFileInfo targetInfo(target);
+ target = QDir::toNativeSeparators(targetInfo.absoluteFilePath());
+ target.prepend("\\??\\");
+ if(target.endsWith('\\') && target.at(target.length()-2) != ':')
+ target.chop(1);
+ }
+ QDir().mkdir(linkName);
+ hFile = CreateFileW( (wchar_t*)linkName.utf16(), GENERIC_WRITE, 0, NULL, OPEN_EXISTING,
+ FILE_FLAG_OPEN_REPARSE_POINT|FILE_FLAG_BACKUP_SEMANTICS, NULL );
+ QVERIFY(hFile != INVALID_HANDLE_VALUE );
+
+ memset( reparseInfo, 0, sizeof( *reparseInfo ));
+ reparseInfo->ReparseTag = IO_REPARSE_TAG_MOUNT_POINT;
+ reparseInfo->ReparseTargetLength = target.size() * sizeof(wchar_t);
+ reparseInfo->ReparseTargetMaximumLength = reparseInfo->ReparseTargetLength + sizeof(wchar_t);
+ target.toWCharArray(reparseInfo->ReparseTarget);
+ reparseInfo->ReparseDataLength = reparseInfo->ReparseTargetLength + 12;
+
+ bool ioc = DeviceIoControl(hFile, FSCTL_SET_REPARSE_POINT, reparseInfo,
+ reparseInfo->ReparseDataLength + REPARSE_MOUNTPOINT_HEADER_SIZE,
+ NULL, 0, &returnedLength, NULL);
+ CloseHandle( hFile );
+ QVERIFY(ioc);
+ }
+#endif
private:
QDir currentDir;
diff --git a/tools/assistant/tools/assistant/assistant.pro b/tools/assistant/tools/assistant/assistant.pro
index eb8cc51..50f5b7e 100644
--- a/tools/assistant/tools/assistant/assistant.pro
+++ b/tools/assistant/tools/assistant/assistant.pro
@@ -12,6 +12,8 @@ DESTDIR = ../../../../bin
target.path = $$[QT_INSTALL_BINS]
INSTALLS += target
DEPENDPATH += ../shared
+DEPENDPATH += .
+INCLUDEPATH += .
# ## Work around a qmake issue when statically linking to
# ## not-yet-installed plugins
@@ -40,11 +42,16 @@ HEADERS += aboutdialog.h \
topicchooser.h \
tracer.h \
xbelsupport.h \
- ../shared/collectionconfiguration.h
+ ../shared/collectionconfiguration.h \
+ openpagesmodel.h \
+ globalactions.h \
+ openpageswidget.h \
+ openpagesmanager.h
+
contains(QT_CONFIG, webkit) {
HEADERS += helpviewer_qwv.h
} else {
- HEADERS += helpviewer_qtb.h
+ HEADERS += helpviewer_qtb.h
}
win32:HEADERS += remotecontrol_win.h
@@ -72,7 +79,11 @@ SOURCES += aboutdialog.cpp \
searchwidget.cpp \
topicchooser.cpp \
xbelsupport.cpp \
- ../shared/collectionconfiguration.cpp
+ ../shared/collectionconfiguration.cpp \
+ openpagesmodel.cpp \
+ globalactions.cpp \
+ openpageswidget.cpp \
+ openpagesmanager.cpp
contains(QT_CONFIG, webkit) {
SOURCES += helpviewer_qwv.cpp
} else {
diff --git a/tools/assistant/tools/assistant/assistant_images.qrc b/tools/assistant/tools/assistant/assistant_images.qrc
index 34918c0..b4f2523 100644
--- a/tools/assistant/tools/assistant/assistant_images.qrc
+++ b/tools/assistant/tools/assistant/assistant_images.qrc
@@ -1,11 +1,10 @@
<RCC>
- <qresource prefix="/trolltech/assistant" >
+ <qresource prefix="/trolltech/assistant">
<file>images/trolltech-logo.png</file>
<file>images/assistant-128.png</file>
<file>images/assistant.png</file>
<file>images/wrap.png</file>
<file>images/bookmark.png</file>
-#mac
<file>images/mac/addtab.png</file>
<file>images/mac/book.png</file>
<file>images/mac/closetab.png</file>
@@ -19,7 +18,6 @@
<file>images/mac/zoomin.png</file>
<file>images/mac/zoomout.png</file>
<file>images/mac/resetzoom.png</file>
-#win
<file>images/win/addtab.png</file>
<file>images/win/book.png</file>
<file>images/win/closetab.png</file>
@@ -33,5 +31,7 @@
<file>images/win/zoomin.png</file>
<file>images/win/zoomout.png</file>
<file>images/win/resetzoom.png</file>
+ <file>images/closebutton.png</file>
+ <file>images/darkclosebutton.png</file>
</qresource>
</RCC>
diff --git a/tools/assistant/tools/assistant/centralwidget.cpp b/tools/assistant/tools/assistant/centralwidget.cpp
index 2359479..6d61570 100644
--- a/tools/assistant/tools/assistant/centralwidget.cpp
+++ b/tools/assistant/tools/assistant/centralwidget.cpp
@@ -38,13 +38,12 @@
** $QT_END_LICENSE$
**
****************************************************************************/
-#include "tracer.h"
#include "centralwidget.h"
+
#include "findwidget.h"
#include "helpenginewrapper.h"
-#include "searchwidget.h"
-#include "mainwindow.h"
+#include "tracer.h"
#include "../shared/collectionconfiguration.h"
#if defined(QT_NO_WEBKIT)
@@ -55,85 +54,37 @@
#include <QtCore/QTimer>
-#include <QtGui/QApplication>
#include <QtGui/QKeyEvent>
-#include <QtGui/QLayout>
-#include <QtGui/QMenu>
-#include <QtGui/QPrinter>
-#include <QtGui/QTabBar>
-#include <QtGui/QTabWidget>
-#include <QtGui/QTextBrowser>
-#include <QtGui/QToolButton>
#include <QtGui/QPageSetupDialog>
#include <QtGui/QPrintDialog>
#include <QtGui/QPrintPreviewDialog>
+#include <QtGui/QPrinter>
+#include <QtGui/QStackedWidget>
+#include <QtGui/QTextBrowser>
+#include <QtGui/QVBoxLayout>
#include <QtHelp/QHelpSearchEngine>
QT_BEGIN_NAMESPACE
namespace {
- HelpViewer* helpViewerFromTabPosition(const QTabWidget *widget,
- const QPoint &point)
- {
- TRACE_OBJ
- QTabBar *tabBar = qFindChild<QTabBar*>(widget);
- for (int i = 0; i < tabBar->count(); ++i) {
- if (tabBar->tabRect(i).contains(point))
- return qobject_cast<HelpViewer*>(widget->widget(i));
- }
- return 0;
- }
CentralWidget *staticCentralWidget = 0;
}
// -- CentralWidget
-CentralWidget::CentralWidget(MainWindow *parent)
+CentralWidget::CentralWidget(QWidget *parent)
: QWidget(parent)
- , lastTabPage(0)
- , tabWidget(0)
, findWidget(0)
, printer(0)
- , usesDefaultCollection(parent->usesDefaultCollection())
- , m_searchWidget(0)
{
TRACE_OBJ
- globalActionList.clear();
staticCentralWidget = this;
QVBoxLayout *vboxLayout = new QVBoxLayout(this);
- QString resourcePath = QLatin1String(":/trolltech/assistant/images/");
vboxLayout->setMargin(0);
- tabWidget = new QTabWidget(this);
-#ifndef Q_OS_MAC
- resourcePath.append(QLatin1String("win"));
-#else
- resourcePath.append(QLatin1String("mac"));
- tabWidget->setDocumentMode(true);
-#endif
-
- connect(tabWidget, SIGNAL(currentChanged(int)), this,
- SLOT(currentPageChanged(int)));
-
- QToolButton *newTabButton = new QToolButton(this);
- newTabButton->setAutoRaise(true);
- newTabButton->setToolTip(tr("Add new page"));
- newTabButton->setIcon(QIcon(resourcePath + QLatin1String("/addtab.png")));
-
- tabWidget->setCornerWidget(newTabButton, Qt::TopLeftCorner);
- connect(newTabButton, SIGNAL(clicked()), this, SLOT(newTab()));
-
- QToolButton *closeTabButton = new QToolButton(this);
- closeTabButton->setEnabled(false);
- closeTabButton->setAutoRaise(true);
- closeTabButton->setToolTip(tr("Close current page"));
- closeTabButton->setIcon(QIcon(resourcePath + QLatin1String("/closetab.png")));
-
- tabWidget->setCornerWidget(closeTabButton, Qt::TopRightCorner);
- connect(closeTabButton, SIGNAL(clicked()), this, SLOT(closeTab()));
-
- vboxLayout->addWidget(tabWidget);
+ m_stackedWidget = new QStackedWidget(this);
+ vboxLayout->addWidget(m_stackedWidget);
findWidget = new FindWidget(this);
vboxLayout->addWidget(findWidget);
@@ -145,14 +96,6 @@ CentralWidget::CentralWidget(MainWindow *parent)
SLOT(find(QString, bool)));
connect(findWidget, SIGNAL(escapePressed()), this, SLOT(activateTab()));
- QTabBar *tabBar = qFindChild<QTabBar*>(tabWidget);
- if (tabBar) {
- tabBar->installEventFilter(this);
- tabBar->setContextMenuPolicy(Qt::CustomContextMenu);
- connect(tabBar, SIGNAL(customContextMenuRequested(QPoint)), this,
- SLOT(showTabBarContextMenu(QPoint)));
- }
-
#if defined(QT_NO_WEBKIT)
QPalette p = palette();
p.setColor(QPalette::Inactive, QPalette::Highlight,
@@ -172,22 +115,19 @@ CentralWidget::~CentralWidget()
QStringList zoomFactors;
QStringList currentPages;
- bool searchAttached = m_searchWidget->isAttached();
-
- int i = searchAttached ? 1 : 0;
- for (; i < tabWidget->count(); ++i) {
- HelpViewer *viewer = qobject_cast<HelpViewer*>(tabWidget->widget(i));
- if (viewer && viewer->source().isValid()) {
- currentPages << viewer->source().toString();
+ for (int i = 0; i < m_stackedWidget->count(); ++i) {
+ const HelpViewer * const viewer = viewerAt(i);
+ const QUrl &source = viewer->source();
+ if (source.isValid()) {
+ currentPages << source.toString();
zoomFactors << QString::number(viewer->scale());
}
}
HelpEngineWrapper &helpEngine = HelpEngineWrapper::instance();
- helpEngine.setLastTabPage(tabWidget->currentIndex());
helpEngine.setLastShownPages(currentPages);
- helpEngine.setSearchWasAttached(searchAttached);
helpEngine.setLastZoomFactors(zoomFactors);
+ helpEngine.setLastTabPage(m_stackedWidget->currentIndex());
}
CentralWidget *CentralWidget::instance()
@@ -196,190 +136,54 @@ CentralWidget *CentralWidget::instance()
return staticCentralWidget;
}
-void CentralWidget::newTab()
-{
- TRACE_OBJ
- HelpViewer *viewer = currentHelpViewer();
-#if !defined(QT_NO_WEBKIT)
- if (viewer && viewer->hasLoadFinished())
-#else
- if (viewer)
-#endif
- setSourceInNewTab(viewer->source());
-}
-
void CentralWidget::zoomIn()
{
TRACE_OBJ
- HelpViewer *viewer = currentHelpViewer();
- if (viewer)
- viewer->scaleUp();
-
- if (tabWidget->currentWidget() == m_searchWidget)
- m_searchWidget->zoomIn();
+ currentHelpViewer()->scaleUp();
}
void CentralWidget::zoomOut()
{
TRACE_OBJ
- HelpViewer *viewer = currentHelpViewer();
- if (viewer)
- viewer->scaleDown();
-
- if (tabWidget->currentWidget() == m_searchWidget)
- m_searchWidget->zoomOut();
-}
-
-void CentralWidget::nextPage()
-{
- TRACE_OBJ
- int index = tabWidget->currentIndex() + 1;
- if (index >= tabWidget->count())
- index = 0;
- tabWidget->setCurrentIndex(index);
+ currentHelpViewer()->scaleDown();
}
void CentralWidget::resetZoom()
{
TRACE_OBJ
- if (HelpViewer *viewer = currentHelpViewer())
- viewer->resetScale();
-
- if (tabWidget->currentWidget() == m_searchWidget)
- m_searchWidget->resetZoom();
-}
-
-void CentralWidget::previousPage()
-{
- TRACE_OBJ
- int index = tabWidget->currentIndex() -1;
- if (index < 0)
- index = tabWidget->count() -1;
- tabWidget->setCurrentIndex(index);
-}
-
-void CentralWidget::closeTab()
-{
- TRACE_OBJ
- HelpViewer *viewer = currentHelpViewer();
- if (!viewer|| tabWidget->count() == 1)
- return;
-
- tabWidget->removeTab(tabWidget->indexOf(viewer));
- QTimer::singleShot(0, viewer, SLOT(deleteLater()));
+ currentHelpViewer()->resetScale();
}
void CentralWidget::setSource(const QUrl &url)
{
TRACE_OBJ
HelpViewer *viewer = currentHelpViewer();
- HelpViewer *lastViewer =
- qobject_cast<HelpViewer*>(tabWidget->widget(lastTabPage));
-
- if (!viewer && !lastViewer) {
- viewer = new HelpViewer(this);
- viewer->installEventFilter(this);
- lastTabPage = tabWidget->addTab(viewer, QString());
- tabWidget->setCurrentIndex(lastTabPage);
- connectSignals();
- } else {
- viewer = lastViewer;
- }
-
viewer->setSource(url);
- currentPageChanged(lastTabPage);
viewer->setFocus(Qt::OtherFocusReason);
- tabWidget->setCurrentIndex(lastTabPage);
- tabWidget->setTabText(lastTabPage, quoteTabTitle(viewer->documentTitle()));
-}
-
-void CentralWidget::setupWidget()
-{
- TRACE_OBJ
- HelpEngineWrapper &helpEngine = HelpEngineWrapper::instance();
- int option = helpEngine.startOption();
- if (option != ShowLastPages) {
- QString homePage;
- if (option == ShowHomePage)
- homePage = helpEngine.homePage();
- else if (option == ShowBlankPage)
- homePage = QLatin1String("about:blank");
- setSource(homePage);
- } else {
- setLastShownPages();
- }
-}
-
-void CentralWidget::setLastShownPages()
-{
- TRACE_OBJ
- HelpEngineWrapper &helpEngine = HelpEngineWrapper::instance();
- const QStringList &lastShownPageList = helpEngine.lastShownPages();
- const int pageCount = lastShownPageList.count();
- if (pageCount == 0) {
- if (usesDefaultCollection)
- setSource(QUrl(QLatin1String("help")));
- else
- setSource(QUrl(QLatin1String("about:blank")));
- return;
- }
- QStringList zoomFactors = helpEngine.lastZoomFactors();
- while (zoomFactors.count() < pageCount)
- zoomFactors.append(CollectionConfiguration::DefaultZoomFactor);
-
- const bool searchIsAttached = m_searchWidget->isAttached();
- const bool searchWasAttached = helpEngine.searchWasAttached();
- int tabToShow = helpEngine.lastTabPage();
- if (searchWasAttached && !searchIsAttached && tabToShow != 0)
- --tabToShow;
- else if (!searchWasAttached && searchIsAttached)
- ++tabToShow;
-
- for (int curTab = 0; curTab < pageCount; ++curTab) {
- const QString &curFile = lastShownPageList.at(curTab);
- if (helpEngine.findFile(curFile).isValid()
- || curFile == QLatin1String("about:blank")) {
- setSourceInNewTab(curFile, zoomFactors.at(curTab).toFloat());
- } else if (curTab + searchIsAttached <= tabToShow)
- --tabToShow;
- }
-
- tabWidget->setCurrentIndex(tabToShow);
}
bool CentralWidget::hasSelection() const
{
TRACE_OBJ
- const HelpViewer *viewer = currentHelpViewer();
- return viewer ? viewer->hasSelection() : false;
+ return currentHelpViewer()->hasSelection();
}
QUrl CentralWidget::currentSource() const
{
TRACE_OBJ
- const HelpViewer *viewer = currentHelpViewer();
- if (viewer)
- return viewer->source();
-
- return QUrl();
+ return currentHelpViewer()->source();
}
QString CentralWidget::currentTitle() const
{
TRACE_OBJ
- const HelpViewer *viewer = currentHelpViewer();
- if (viewer)
- return viewer->documentTitle();
-
- return QString();
+ return currentHelpViewer()->documentTitle();
}
void CentralWidget::copySelection()
{
TRACE_OBJ
- HelpViewer *viewer = currentHelpViewer();
- if (viewer)
- viewer->copy();
+ currentHelpViewer()->copy();
}
void CentralWidget::showTextSearch()
@@ -402,11 +206,7 @@ void CentralWidget::print()
TRACE_OBJ
#ifndef QT_NO_PRINTER
HelpViewer *viewer = currentHelpViewer();
- if (!viewer)
- return;
-
initPrinter();
-
QPrintDialog dlg(printer, this);
#if defined(QT_NO_WEBKIT)
if (viewer->textCursor().hasSelection())
@@ -437,9 +237,7 @@ void CentralWidget::printPreview(QPrinter *p)
{
TRACE_OBJ
#ifndef QT_NO_PRINTER
- HelpViewer *viewer = currentHelpViewer();
- if (viewer)
- viewer->print(p);
+ currentHelpViewer()->print(p);
#endif
}
@@ -453,236 +251,66 @@ void CentralWidget::pageSetup()
#endif
}
-bool CentralWidget::isHomeAvailable() const
-{
- TRACE_OBJ
- return currentHelpViewer() ? true : false;
-}
-
void CentralWidget::home()
{
TRACE_OBJ
- HelpViewer *viewer = currentHelpViewer();
- if (viewer)
- viewer->home();
+ currentHelpViewer()->home();
}
bool CentralWidget::isForwardAvailable() const
{
TRACE_OBJ
- const HelpViewer *viewer = currentHelpViewer();
- if (viewer)
- return viewer->isForwardAvailable();
-
- return false;
+ return currentHelpViewer()->isForwardAvailable();
}
void CentralWidget::forward()
{
TRACE_OBJ
- HelpViewer *viewer = currentHelpViewer();
- if (viewer)
- viewer->forward();
+ currentHelpViewer()->forward();
}
bool CentralWidget::isBackwardAvailable() const
{
TRACE_OBJ
- const HelpViewer *viewer = currentHelpViewer();
- if (viewer)
- return viewer->isBackwardAvailable();
-
- return false;
+ return currentHelpViewer()->isBackwardAvailable();
}
void CentralWidget::backward()
{
TRACE_OBJ
- HelpViewer *viewer = currentHelpViewer();
- if (viewer)
- viewer->backward();
-}
-
-
-QList<QAction*> CentralWidget::globalActions() const
-{
- TRACE_OBJ
- return globalActionList;
+ currentHelpViewer()->backward();
}
-void CentralWidget::setGlobalActions(const QList<QAction*> &actions)
+void CentralWidget::connectSignals(HelpViewer *page)
{
TRACE_OBJ
- globalActionList = actions;
-}
-
-void CentralWidget::setSourceInNewTab(const QUrl &url, qreal zoom)
-{
- TRACE_OBJ
- if (HelpViewer *viewer = currentHelpViewer()) {
- if (viewer->launchWithExternalApp(url))
- return;
- }
-
- HelpViewer *viewer = new HelpViewer(this, zoom);
- viewer->installEventFilter(this);
- viewer->setSource(url);
- viewer->setFocus(Qt::OtherFocusReason);
- tabWidget->setCurrentIndex(tabWidget->addTab(viewer,
- quoteTabTitle(viewer->documentTitle())));
- connectSignals();
-}
-
-HelpViewer *CentralWidget::newEmptyTab()
-{
- TRACE_OBJ
- HelpViewer *viewer = new HelpViewer(this);
- viewer->installEventFilter(this);
- viewer->setFocus(Qt::OtherFocusReason);
-#if defined(QT_NO_WEBKIT)
- viewer->setDocumentTitle(tr("unknown"));
-#endif
- tabWidget->setCurrentIndex(tabWidget->addTab(viewer, tr("unknown")));
-
- connectSignals();
- return viewer;
-}
-
-void CentralWidget::connectSignals()
-{
- TRACE_OBJ
- const HelpViewer *viewer = currentHelpViewer();
- if (viewer) {
- connect(viewer, SIGNAL(copyAvailable(bool)), this,
- SIGNAL(copyAvailable(bool)));
- connect(viewer, SIGNAL(forwardAvailable(bool)), this,
- SIGNAL(forwardAvailable(bool)));
- connect(viewer, SIGNAL(backwardAvailable(bool)), this,
- SIGNAL(backwardAvailable(bool)));
- connect(viewer, SIGNAL(sourceChanged(QUrl)), this,
- SIGNAL(sourceChanged(QUrl)));
- connect(viewer, SIGNAL(highlighted(QString)), this,
+ connect(page, SIGNAL(copyAvailable(bool)), this, SIGNAL(copyAvailable(bool)));
+ connect(page, SIGNAL(forwardAvailable(bool)), this,
+ SIGNAL(forwardAvailable(bool)));
+ connect(page, SIGNAL(backwardAvailable(bool)), this,
+ SIGNAL(backwardAvailable(bool)));
+ connect(page, SIGNAL(sourceChanged(QUrl)), this,
+ SLOT(handleSourceChanged(QUrl)));
+ connect(page, SIGNAL(highlighted(QString)), this,
SIGNAL(highlighted(QString)));
- connect(viewer, SIGNAL(sourceChanged(QUrl)), this,
- SLOT(setTabTitle(QUrl)));
- }
}
HelpViewer* CentralWidget::viewerAt(int index) const
{
TRACE_OBJ
- return qobject_cast<HelpViewer*>(tabWidget->widget(index));
+ return static_cast<HelpViewer*>(m_stackedWidget->widget(index));
}
HelpViewer* CentralWidget::currentHelpViewer() const
{
TRACE_OBJ
- return qobject_cast<HelpViewer*>(tabWidget->currentWidget());
+ return static_cast<HelpViewer *>(m_stackedWidget->currentWidget());
}
-void CentralWidget::activateTab(bool onlyHelpViewer)
+void CentralWidget::activateTab()
{
TRACE_OBJ
- if (currentHelpViewer()) {
- currentHelpViewer()->setFocus();
- } else {
- int idx = 0;
- if (onlyHelpViewer)
- idx = lastTabPage;
- tabWidget->setCurrentIndex(idx);
- tabWidget->currentWidget()->setFocus();
- }
-}
-
-void CentralWidget::setTabTitle(const QUrl &url)
-{
- TRACE_OBJ
- Q_UNUSED(url)
-#if !defined(QT_NO_WEBKIT)
- QTabBar *tabBar = qFindChild<QTabBar*>(tabWidget);
- for (int tab = 0; tab < tabBar->count(); ++tab) {
- HelpViewer *viewer = qobject_cast<HelpViewer*>(tabWidget->widget(tab));
- if (viewer) {
- tabWidget->setTabText(tab,
- quoteTabTitle(viewer->documentTitle().trimmed()));
- }
- }
-#else
- HelpViewer *viewer = currentHelpViewer();
- if (viewer) {
- tabWidget->setTabText(lastTabPage,
- quoteTabTitle(viewer->documentTitle().trimmed()));
- }
-#endif
-}
-
-void CentralWidget::currentPageChanged(int index)
-{
- TRACE_OBJ
- const HelpViewer *viewer = currentHelpViewer();
- if (viewer)
- lastTabPage = index;
-
- QWidget *widget = tabWidget->cornerWidget(Qt::TopRightCorner);
- widget->setEnabled(viewer && enableTabCloseAction());
-
- widget = tabWidget->cornerWidget(Qt::TopLeftCorner);
- widget->setEnabled(viewer ? true : false);
-
- emit currentViewerChanged();
-}
-
-void CentralWidget::showTabBarContextMenu(const QPoint &point)
-{
- TRACE_OBJ
- HelpViewer *viewer = helpViewerFromTabPosition(tabWidget, point);
- if (!viewer)
- return;
-
- QTabBar *tabBar = qFindChild<QTabBar*>(tabWidget);
-
- QMenu menu(QLatin1String(""), tabBar);
- QAction *newPage = menu.addAction(tr("Add New Page"));
-
- bool enableAction = enableTabCloseAction();
- QAction *closePage = menu.addAction(tr("Close This Page"));
- closePage->setEnabled(enableAction);
-
- QAction *closePages = menu.addAction(tr("Close Other Pages"));
- closePages->setEnabled(enableAction);
-
- menu.addSeparator();
-
- QAction *newBookmark = menu.addAction(tr("Add Bookmark for this Page..."));
- const QString &url = viewer->source().toString();
- if (url.isEmpty() || url == QLatin1String("about:blank"))
- newBookmark->setEnabled(false);
-
- QAction *pickedAction = menu.exec(tabBar->mapToGlobal(point));
- if (pickedAction == newPage)
- setSourceInNewTab(viewer->source());
-
- if (pickedAction == closePage) {
- tabWidget->removeTab(tabWidget->indexOf(viewer));
- QTimer::singleShot(0, viewer, SLOT(deleteLater()));
- }
-
- if (pickedAction == closePages) {
- int currentPage = tabWidget->indexOf(viewer);
- for (int i = tabBar->count() -1; i >= 0; --i) {
- viewer = qobject_cast<HelpViewer*>(tabWidget->widget(i));
- if (i != currentPage && viewer) {
- tabWidget->removeTab(i);
- QTimer::singleShot(0, viewer, SLOT(deleteLater()));
-
- if (i < currentPage)
- --currentPage;
- }
- }
- }
-
- if (pickedAction == newBookmark)
- emit addBookmark(viewer->documentTitle(), viewer->source().toString());
+ currentHelpViewer()->setFocus();
}
bool CentralWidget::eventFilter(QObject *object, QEvent *e)
@@ -711,25 +339,6 @@ bool CentralWidget::eventFilter(QObject *object, QEvent *e)
}
}
- if (qobject_cast<QTabBar*>(object)) {
- const bool dblClick = e->type() == QEvent::MouseButtonDblClick;
- if ((e->type() == QEvent::MouseButtonRelease) || dblClick) {
- QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(e);
- HelpViewer *viewer = helpViewerFromTabPosition(tabWidget,
- mouseEvent->pos());
- if (viewer) {
- if ((mouseEvent->button() == Qt::MidButton) || dblClick) {
- if (availableHelpViewer() > 1) {
- tabWidget->removeTab(tabWidget->indexOf(viewer));
- QTimer::singleShot(0, viewer, SLOT(deleteLater()));
- currentPageChanged(tabWidget->currentIndex());
- return true;
- }
- }
- }
- }
- }
-
return QWidget::eventFilter(object, e);
}
@@ -782,34 +391,33 @@ bool CentralWidget::findInWebPage(const QString &ttf, bool forward)
{
TRACE_OBJ
#if !defined(QT_NO_WEBKIT)
- if (HelpViewer *viewer = currentHelpViewer()) {
- bool found = false;
- QWebPage::FindFlags options;
- if (!ttf.isEmpty()) {
- if (!forward)
- options |= QWebPage::FindBackward;
+ HelpViewer *viewer = currentHelpViewer();
+ bool found = false;
+ QWebPage::FindFlags options;
+ if (!ttf.isEmpty()) {
+ if (!forward)
+ options |= QWebPage::FindBackward;
- if (findWidget->caseSensitive())
- options |= QWebPage::FindCaseSensitively;
+ if (findWidget->caseSensitive())
+ options |= QWebPage::FindCaseSensitively;
- found = viewer->findText(ttf, options);
- findWidget->setTextWrappedVisible(false);
+ found = viewer->findText(ttf, options);
+ findWidget->setTextWrappedVisible(false);
- if (!found) {
- options |= QWebPage::FindWrapsAroundDocument;
- found = viewer->findText(ttf, options);
- if (found)
- findWidget->setTextWrappedVisible(true);
- }
+ if (!found) {
+ options |= QWebPage::FindWrapsAroundDocument;
+ found = viewer->findText(ttf, options);
+ if (found)
+ findWidget->setTextWrappedVisible(true);
}
- // force highlighting of all other matches, also when empty (clear)
- options = QWebPage::HighlightAllOccurrences;
- if (findWidget->caseSensitive())
- options |= QWebPage::FindCaseSensitively;
- viewer->findText(QLatin1String(""), options);
- viewer->findText(ttf, options);
- return found;
}
+ // force highlighting of all other matches, also when empty (clear)
+ options = QWebPage::HighlightAllOccurrences;
+ if (findWidget->caseSensitive())
+ options |= QWebPage::FindCaseSensitively;
+ viewer->findText(QLatin1String(""), options);
+ viewer->findText(ttf, options);
+ return found;
// this needs to stay, case for active search results page
return findInTextBrowser(ttf, forward);
@@ -824,8 +432,6 @@ bool CentralWidget::findInTextBrowser(const QString &ttf, bool forward)
{
TRACE_OBJ
QTextBrowser *browser = qobject_cast<QTextBrowser*>(currentHelpViewer());
- if (tabWidget->currentWidget() == m_searchWidget)
- browser = qFindChild<QTextBrowser*>(m_searchWidget);
if (!browser || ttf.isEmpty())
return false;
@@ -872,95 +478,10 @@ bool CentralWidget::findInTextBrowser(const QString &ttf, bool forward)
void CentralWidget::updateBrowserFont()
{
TRACE_OBJ
- const bool searchAttached = searchWidgetAttached();
- if (searchAttached) {
- HelpEngineWrapper &helpEngine = HelpEngineWrapper::instance();
- m_searchWidget->setFont(helpEngine.usesBrowserFont()
- ? helpEngine.browserFont() : qApp->font());
- }
-
- const int count = tabWidget->count();
- if (HelpViewer* viewer = viewerAt(count - 1)) {
- const QFont &font = viewer->viewerFont();
- for (int i = searchAttached ? 1 : 0; i < count; ++i)
- viewerAt(i)->setViewerFont(font);
- }
-}
-
-bool CentralWidget::searchWidgetAttached() const
-{
- TRACE_OBJ
- return m_searchWidget && m_searchWidget->isAttached();
-}
-
-void CentralWidget::createSearchWidget(QHelpSearchEngine *searchEngine)
-{
- TRACE_OBJ
- if (m_searchWidget)
- return;
-
- m_searchWidget = new SearchWidget(searchEngine, this);
- connect(m_searchWidget, SIGNAL(requestShowLink(QUrl)), this,
- SLOT(setSourceFromSearch(QUrl)));
- connect(m_searchWidget, SIGNAL(requestShowLinkInNewTab(QUrl)), this,
- SLOT(setSourceFromSearchInNewTab(QUrl)));
-
- HelpEngineWrapper &helpEngine = HelpEngineWrapper::instance();
- m_searchWidget->setFont(!helpEngine.usesBrowserFont() ? qApp->font()
- : helpEngine.browserFont());
-}
-
-void CentralWidget::activateSearchWidget(bool updateLastTabPage)
-{
- TRACE_OBJ
- if (!m_searchWidget)
- createSearchWidget(HelpEngineWrapper::instance().searchEngine());
-
- if (!m_searchWidget->isAttached()) {
- tabWidget->insertTab(0, m_searchWidget, tr("Search"));
- m_searchWidget->setAttached(true);
-
- if (updateLastTabPage)
- lastTabPage++;
- }
-
- tabWidget->setCurrentWidget(m_searchWidget);
- m_searchWidget->setFocus();
-}
-
-void CentralWidget::removeSearchWidget()
-{
- TRACE_OBJ
- if (searchWidgetAttached()) {
- tabWidget->removeTab(0);
- m_searchWidget->setAttached(false);
- }
-}
-
-int CentralWidget::availableHelpViewer() const
-{
- TRACE_OBJ
- int count = tabWidget->count();
- if (searchWidgetAttached())
- count--;
- return count;
-}
-
-bool CentralWidget::enableTabCloseAction() const
-{
- TRACE_OBJ
- int minTabCount = 1;
- if (searchWidgetAttached())
- minTabCount = 2;
-
- return (tabWidget->count() > minTabCount);
-}
-
-QString CentralWidget::quoteTabTitle(const QString &title) const
-{
- TRACE_OBJ
- QString s = title;
- return s.replace(QLatin1Char('&'), QLatin1String("&&"));
+ const int count = m_stackedWidget->count();
+ const QFont &font = viewerAt(count - 1)->viewerFont();
+ for (int i = 0; i < count; ++i)
+ viewerAt(i)->setViewerFont(font);
}
void
@@ -977,25 +498,10 @@ CentralWidget::setSourceFromSearch(const QUrl &url)
}
void
-CentralWidget::setSourceFromSearchInNewTab(const QUrl &url)
-{
- TRACE_OBJ
- setSourceInNewTab(url);
-#if defined(QT_NO_WEBKIT)
- highlightSearchTerms();
-#else
- connect(currentHelpViewer(), SIGNAL(loadFinished(bool)), this,
- SLOT(highlightSearchTerms()));
-#endif
-}
-
-void
CentralWidget::highlightSearchTerms()
{
TRACE_OBJ
HelpViewer *viewer = currentHelpViewer();
- if (!viewer)
- return;
QHelpSearchEngine *searchEngine =
HelpEngineWrapper::instance().searchEngine();
@@ -1058,48 +564,48 @@ CentralWidget::highlightSearchTerms()
#endif
}
-
-void CentralWidget::closeOrReloadTabs(const QList<int> &indices, bool tryReload)
+void CentralWidget::addPage(HelpViewer *page, bool fromSearch)
{
TRACE_OBJ
- QList<int> sortedIndices = indices;
- qSort(sortedIndices);
- for (int i = sortedIndices.count(); --i >= 0;) {
- const int tab = sortedIndices.at(i);
- bool close = true;
- if (tryReload) {
- HelpViewer *viewer =
- qobject_cast<HelpViewer*>(tabWidget->widget(tab));
- if (HelpEngineWrapper::instance().findFile(viewer->source()).isValid()) {
- viewer->reload();
- close = false;
- }
- }
- if (close)
- closeTabAt(tab);
+ page->installEventFilter(this);
+ page->setFocus(Qt::OtherFocusReason);
+ connectSignals(page);
+ m_stackedWidget->addWidget(page);
+ if (fromSearch) {
+#if defined(QT_NO_WEBKIT)
+ highlightSearchTerms();
+#else
+ connect(currentHelpViewer(), SIGNAL(loadFinished(bool)), this,
+ SLOT(highlightSearchTerms()));
+#endif
}
- if (availableHelpViewer() == 0)
- setSource(QUrl(QLatin1String("about:blank")));
}
-void CentralWidget::closeTabAt(int index)
+void CentralWidget::removePage(int index)
{
TRACE_OBJ
- HelpViewer *viewer = qobject_cast<HelpViewer*>(tabWidget->widget(index));
- tabWidget->removeTab(index);
- QTimer::singleShot(0, viewer, SLOT(deleteLater()));
+ const bool currentChanged = index == currentIndex();
+ m_stackedWidget->removeWidget(m_stackedWidget->widget(index));
+ if (currentChanged)
+ emit currentViewerChanged();
}
-QMap<int, QString> CentralWidget::currentSourceFileList() const
+void CentralWidget::setCurrentPage(HelpViewer *page)
{
TRACE_OBJ
- QMap<int, QString> sourceList;
- for (int i = 0; i < tabWidget->count(); ++i) {
- HelpViewer *viewer = qobject_cast<HelpViewer*>(tabWidget->widget(i));
- if (viewer && viewer->source().isValid())
- sourceList.insert(i, viewer->source().host());
- }
- return sourceList;
+ m_stackedWidget->setCurrentWidget(page);
+ emit currentViewerChanged();
+}
+
+int CentralWidget::currentIndex() const
+{
+ return m_stackedWidget->currentIndex();
+}
+
+void CentralWidget::handleSourceChanged(const QUrl &url)
+{
+ if (sender() == currentHelpViewer())
+ emit sourceChanged(url);
}
QT_END_NAMESPACE
diff --git a/tools/assistant/tools/assistant/centralwidget.h b/tools/assistant/tools/assistant/centralwidget.h
index f286ff7..9b8db30 100644
--- a/tools/assistant/tools/assistant/centralwidget.h
+++ b/tools/assistant/tools/assistant/centralwidget.h
@@ -48,52 +48,36 @@ QT_BEGIN_NAMESPACE
class FindWidget;
class HelpViewer;
-class MainWindow;
-class QHelpSearchEngine;
-class QTabWidget;
-class SearchWidget;
+class QStackedWidget;
class CentralWidget : public QWidget
{
Q_OBJECT
public:
- CentralWidget(MainWindow *parent);
+ CentralWidget(QWidget *parent);
~CentralWidget();
- void setupWidget();
bool hasSelection() const;
QUrl currentSource() const;
QString currentTitle() const;
- bool isHomeAvailable() const;
bool isForwardAvailable() const;
bool isBackwardAvailable() const;
- QList<QAction*> globalActions() const;
- void setGlobalActions(const QList<QAction*> &actions);
HelpViewer *viewerAt(int index) const;
HelpViewer *currentHelpViewer() const;
- bool searchWidgetAttached() const;
- void createSearchWidget(QHelpSearchEngine *searchEngine);
- void activateSearchWidget(bool updateLastTabPage = false);
- void removeSearchWidget();
-
- int availableHelpViewer() const;
- bool enableTabCloseAction() const;
-
- void closeOrReloadTabs(const QList<int> &indices, bool tryReload);
- void closeTabAt(int index);
- QMap<int, QString> currentSourceFileList() const;
+ void addPage(HelpViewer *page, bool fromSearch = false);
+ void removePage(int index);
+ void setCurrentPage(HelpViewer *page);
+ int currentIndex() const;
static CentralWidget *instance();
public slots:
void zoomIn();
void zoomOut();
- void nextPage();
void resetZoom();
- void previousPage();
void copySelection();
void showTextSearch();
void print();
@@ -101,13 +85,12 @@ public slots:
void printPreview();
void updateBrowserFont();
void setSource(const QUrl &url);
- void setSourceInNewTab(const QUrl &url, qreal zoom = 0.0);
- HelpViewer *newEmptyTab();
+ void setSourceFromSearch(const QUrl &url);
void home();
void forward();
void backward();
- void activateTab(bool onlyHelpViewer = false);
+ void activateTab();
void findNext();
void findPrevious();
@@ -126,35 +109,21 @@ protected:
void keyPressEvent(QKeyEvent *);
private slots:
- void newTab();
- void closeTab();
- void setTabTitle(const QUrl& url);
- void currentPageChanged(int index);
- void showTabBarContextMenu(const QPoint &point);
void printPreview(QPrinter *printer);
- void setSourceFromSearch(const QUrl &url);
- void setSourceFromSearchInNewTab(const QUrl &url);
void highlightSearchTerms();
+ void handleSourceChanged(const QUrl &url);
private:
- void connectSignals();
+ void connectSignals(HelpViewer *page);
bool eventFilter(QObject *object, QEvent *e);
bool findInWebPage(const QString &ttf, bool forward);
bool findInTextBrowser(const QString &ttf, bool forward);
void initPrinter();
- QString quoteTabTitle(const QString &title) const;
- void setLastShownPages();
private:
- int lastTabPage;
- QList<QAction*> globalActionList;
-
- QTabWidget *tabWidget;
+ QStackedWidget *m_stackedWidget;
FindWidget *findWidget;
QPrinter *printer;
- bool usesDefaultCollection;
-
- SearchWidget *m_searchWidget;
};
QT_END_NAMESPACE
diff --git a/tools/assistant/tools/assistant/contentwindow.cpp b/tools/assistant/tools/assistant/contentwindow.cpp
index e0347c8..3af4d34 100644
--- a/tools/assistant/tools/assistant/contentwindow.cpp
+++ b/tools/assistant/tools/assistant/contentwindow.cpp
@@ -44,6 +44,7 @@
#include "centralwidget.h"
#include "helpenginewrapper.h"
#include "helpviewer.h"
+#include "openpagesmanager.h"
#include <QtGui/QLayout>
#include <QtGui/QFocusEvent>
@@ -145,7 +146,7 @@ bool ContentWindow::eventFilter(QObject *o, QEvent *e)
if (contentModel) {
QHelpContentItem *itm = contentModel->contentItemAt(index);
if (itm && AbstractHelpViewer::canOpenPage(itm->url().path()))
- CentralWidget::instance()->setSourceInNewTab(itm->url());
+ OpenPagesManager::instance()->createPage(itm->url());
}
} else if (button == Qt::LeftButton) {
itemClicked(index);
@@ -179,7 +180,7 @@ void ContentWindow::showContextMenu(const QPoint &pos)
if (curTab == action)
emit linkActivated(itm->url());
else if (newTab == action)
- CentralWidget::instance()->setSourceInNewTab(itm->url());
+ OpenPagesManager::instance()->createPage(itm->url());
}
void ContentWindow::itemClicked(const QModelIndex &index)
diff --git a/tools/assistant/tools/assistant/globalactions.cpp b/tools/assistant/tools/assistant/globalactions.cpp
new file mode 100644
index 0000000..de47da0
--- /dev/null
+++ b/tools/assistant/tools/assistant/globalactions.cpp
@@ -0,0 +1,163 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Assistant module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "globalactions.h"
+
+#include "centralwidget.h"
+#include "tracer.h"
+
+#include <QtGui/QAction>
+
+GlobalActions *GlobalActions::instance(QObject *parent)
+{
+ Q_ASSERT(!m_instance != !parent);
+ if (!m_instance)
+ m_instance = new GlobalActions(parent);
+ return m_instance;
+}
+
+GlobalActions::GlobalActions(QObject *parent) : QObject(parent)
+{
+ TRACE_OBJ
+
+ // TODO: Put resource path in misc class
+ QString resourcePath = QLatin1String(":/trolltech/assistant/images/");
+#ifdef Q_OS_MAC
+ resourcePath.append(QLatin1String("mac"));
+#else
+ resourcePath.append(QLatin1String("win"));
+#endif
+ CentralWidget *centralWidget = CentralWidget::instance();
+
+ m_backAction = new QAction(tr("&Back"), parent);
+ m_backAction->setEnabled(false);
+ m_backAction->setShortcuts(QKeySequence::Back);
+ m_backAction->setIcon(QIcon(resourcePath + QLatin1String("/previous.png")));
+ connect(m_backAction, SIGNAL(triggered()), centralWidget, SLOT(backward()));
+ m_actionList << m_backAction;
+
+ m_nextAction = new QAction(tr("&Forward"), parent);
+ m_nextAction->setPriority(QAction::LowPriority);
+ m_nextAction->setEnabled(false);
+ m_nextAction->setShortcuts(QKeySequence::Forward);
+ m_nextAction->setIcon(QIcon(resourcePath + QLatin1String("/next.png")));
+ connect(m_nextAction, SIGNAL(triggered()), centralWidget, SLOT(forward()));
+ m_actionList << m_nextAction;
+
+ m_homeAction = new QAction(tr("&Home"), parent);
+ m_homeAction->setShortcut(tr("ALT+Home"));
+ m_homeAction->setIcon(QIcon(resourcePath + QLatin1String("/home.png")));
+ connect(m_homeAction, SIGNAL(triggered()), centralWidget, SLOT(home()));
+ m_actionList << m_homeAction;
+
+ QAction *separator = new QAction(parent);
+ separator->setSeparator(true);
+ m_actionList << separator;
+
+ m_zoomInAction = new QAction(tr("Zoom &in"), parent);
+ m_zoomInAction->setPriority(QAction::LowPriority);
+ m_zoomInAction->setIcon(QIcon(resourcePath + QLatin1String("/zoomin.png")));
+ m_zoomInAction->setShortcut(QKeySequence::ZoomIn);
+ connect(m_zoomInAction, SIGNAL(triggered()), centralWidget, SLOT(zoomIn()));
+ m_actionList << m_zoomInAction;
+
+ m_zoomOutAction = new QAction(tr("Zoom &out"), parent);
+ m_zoomOutAction->setPriority(QAction::LowPriority);
+ m_zoomOutAction->setIcon(QIcon(resourcePath + QLatin1String("/zoomout.png")));
+ m_zoomOutAction->setShortcut(QKeySequence::ZoomOut);
+ connect(m_zoomOutAction, SIGNAL(triggered()), centralWidget, SLOT(zoomOut()));
+ m_actionList << m_zoomOutAction;
+
+ separator = new QAction(parent);
+ separator->setSeparator(true);
+ m_actionList << separator;
+
+ m_copyAction = new QAction(tr("&Copy selected Text"), parent);
+ m_copyAction->setPriority(QAction::LowPriority);
+ m_copyAction->setIconText("&Copy");
+ m_copyAction->setIcon(QIcon(resourcePath + QLatin1String("/editcopy.png")));
+ m_copyAction->setShortcuts(QKeySequence::Copy);
+ m_copyAction->setEnabled(false);
+ connect(m_copyAction, SIGNAL(triggered()), centralWidget, SLOT(copySelection()));
+ m_actionList << m_copyAction;
+
+ m_printAction = new QAction(tr("&Print..."), parent);
+ m_printAction->setPriority(QAction::LowPriority);
+ m_printAction->setIcon(QIcon(resourcePath + QLatin1String("/print.png")));
+ m_printAction->setShortcut(QKeySequence::Print);
+ connect(m_printAction, SIGNAL(triggered()), centralWidget, SLOT(print()));
+ m_actionList << m_printAction;
+
+ m_findAction = new QAction(tr("&Find in Text..."), parent);
+ m_findAction->setIconText(tr("&Find"));
+ m_findAction->setIcon(QIcon(resourcePath + QLatin1String("/find.png")));
+ m_findAction->setShortcuts(QKeySequence::Find);
+ connect(m_findAction, SIGNAL(triggered()), centralWidget, SLOT(showTextSearch()));
+ m_actionList << m_findAction;
+
+#ifdef Q_WS_X11
+ m_backAction->setIcon(QIcon::fromTheme("go-previous" , m_backAction->icon()));
+ m_nextAction->setIcon(QIcon::fromTheme("go-next" , m_nextAction->icon()));
+ m_zoomInAction->setIcon(QIcon::fromTheme("zoom-in" , m_zoomInAction->icon()));
+ m_zoomOutAction->setIcon(QIcon::fromTheme("zoom-out" , m_zoomOutAction->icon()));
+ m_copyAction->setIcon(QIcon::fromTheme("edit-copy" , m_copyAction->icon()));
+ m_findAction->setIcon(QIcon::fromTheme("edit-find" , m_findAction->icon()));
+ m_homeAction->setIcon(QIcon::fromTheme("go-home" , m_homeAction->icon()));
+ m_printAction->setIcon(QIcon::fromTheme("document-print" , m_printAction->icon()));
+#endif
+}
+
+void GlobalActions::updateActions()
+{
+ TRACE_OBJ
+ CentralWidget *centralWidget = CentralWidget::instance();
+ m_copyAction->setEnabled(centralWidget->hasSelection());
+ m_nextAction->setEnabled(centralWidget->isForwardAvailable());
+ m_backAction->setEnabled(centralWidget->isBackwardAvailable());
+}
+
+void GlobalActions::setCopyAvailable(bool available)
+{
+ TRACE_OBJ
+ m_copyAction->setEnabled(available);
+}
+
+GlobalActions *GlobalActions::m_instance = 0;
diff --git a/tools/assistant/tools/assistant/globalactions.h b/tools/assistant/tools/assistant/globalactions.h
new file mode 100644
index 0000000..e53e08f
--- /dev/null
+++ b/tools/assistant/tools/assistant/globalactions.h
@@ -0,0 +1,91 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Assistant module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef GLOBALACTION_H
+#define GLOBALACTION_H
+
+#include <QtCore/QList>
+#include <QtCore/QObject>
+
+QT_BEGIN_NAMESPACE
+
+class QAction;
+
+class GlobalActions : public QObject
+{
+ Q_OBJECT
+ Q_DISABLE_COPY(GlobalActions)
+public:
+ static GlobalActions *instance(QObject *parent = 0);
+
+ QList<QAction *> actionList() const { return m_actionList; }
+ QAction *backAction() const { return m_backAction; }
+ QAction *nextAction() const { return m_nextAction; }
+ QAction *homeAction() const { return m_homeAction; }
+ QAction *zoomInAction() const { return m_zoomInAction; }
+ QAction *zoomOutAction() const { return m_zoomOutAction; }
+ QAction *copyAction() const { return m_copyAction; }
+ QAction *printAction() const { return m_printAction; }
+ QAction *findAction() const { return m_findAction; }
+
+ Q_SLOT void updateActions();
+ Q_SLOT void setCopyAvailable(bool available);
+
+private:
+ GlobalActions(QObject *parent);
+
+ static GlobalActions *m_instance;
+
+ QAction *m_backAction;
+ QAction *m_nextAction;
+ QAction *m_homeAction;
+ QAction *m_zoomInAction;
+ QAction *m_zoomOutAction;
+ QAction *m_copyAction;
+ QAction *m_printAction;
+ QAction *m_findAction;
+
+ QList<QAction *> m_actionList;
+};
+
+QT_END_NAMESPACE
+
+#endif // GLOBALACTION_H
diff --git a/tools/assistant/tools/assistant/helpenginewrapper.cpp b/tools/assistant/tools/assistant/helpenginewrapper.cpp
index 9748702..60b83f7 100644
--- a/tools/assistant/tools/assistant/helpenginewrapper.cpp
+++ b/tools/assistant/tools/assistant/helpenginewrapper.cpp
@@ -569,18 +569,6 @@ void HelpEngineWrapper::setLastTabPage(int lastPage)
CollectionConfiguration::setLastTabPage(*d->m_helpEngine, lastPage);
}
-bool HelpEngineWrapper::searchWasAttached() const
-{
- TRACE_OBJ
- return d->m_helpEngine->customValue(SearchWasAttachedKey).toBool();
-}
-
-void HelpEngineWrapper::setSearchWasAttached(bool attached)
-{
- TRACE_OBJ
- d->m_helpEngine->setCustomValue(SearchWasAttachedKey, attached);
-}
-
int HelpEngineWrapper::startOption() const
{
TRACE_OBJ
diff --git a/tools/assistant/tools/assistant/helpenginewrapper.h b/tools/assistant/tools/assistant/helpenginewrapper.h
index c1041b6..f1a381a 100644
--- a/tools/assistant/tools/assistant/helpenginewrapper.h
+++ b/tools/assistant/tools/assistant/helpenginewrapper.h
@@ -170,9 +170,6 @@ public:
int startOption() const;
void setStartOption(int option);
- bool searchWasAttached() const;
- void setSearchWasAttached(bool attached);
-
bool hasFontSettings() const;
bool usesAppFont() const;
void setUseAppFont(bool useAppFont);
diff --git a/tools/assistant/tools/assistant/helpviewer_qtb.cpp b/tools/assistant/tools/assistant/helpviewer_qtb.cpp
index 7f82b56..78890b9 100644
--- a/tools/assistant/tools/assistant/helpviewer_qtb.cpp
+++ b/tools/assistant/tools/assistant/helpviewer_qtb.cpp
@@ -40,8 +40,9 @@
****************************************************************************/
#include "helpviewer_qtb.h"
-#include "centralwidget.h"
+#include "globalactions.h"
#include "helpenginewrapper.h"
+#include "openpagesmanager.h"
#include "tracer.h"
#include <QtCore/QStringBuilder>
@@ -53,12 +54,10 @@
QT_BEGIN_NAMESPACE
-HelpViewer::HelpViewer(CentralWidget *parent, qreal zoom)
- : QTextBrowser(parent)
- , zoomCount(zoom)
+HelpViewer::HelpViewer(qreal zoom)
+ : zoomCount(zoom)
, controlPressed(false)
, lastAnchor(QString())
- , parentWidget(parent)
, helpEngine(HelpEngineWrapper::instance())
, forceFont(false)
{
@@ -69,6 +68,7 @@ HelpViewer::HelpViewer(CentralWidget *parent, qreal zoom)
QFont font = viewerFont();
font.setPointSize(int(font.pointSize() + zoom));
setViewerFont(font);
+ connect(this, SIGNAL(sourceChanged(QUrl), this, SIGNAL(titleChanged()));
}
HelpViewer::~HelpViewer()
@@ -188,7 +188,7 @@ void HelpViewer::openLinkInNewTab()
if(lastAnchor.isEmpty())
return;
- parentWidget->setSourceInNewTab(QUrl(lastAnchor));
+ OpenPagesManager::instance()->createPage(QUrl(lastAnchor));
lastAnchor.clear();
}
@@ -234,7 +234,8 @@ void HelpViewer::contextMenuEvent(QContextMenuEvent *e)
SLOT(openLinkInNewTab()));
menu.addSeparator();
}
- menu.addActions(parentWidget->globalActions());
+
+ menu.addActions(GlobalActions::instance()->actionList());
QAction *action = menu.exec(e->globalPos());
if (action == copyAnchorAction)
QApplication::clipboard()->setText(link.toString());
diff --git a/tools/assistant/tools/assistant/helpviewer_qtb.h b/tools/assistant/tools/assistant/helpviewer_qtb.h
index acb734b..065557e 100644
--- a/tools/assistant/tools/assistant/helpviewer_qtb.h
+++ b/tools/assistant/tools/assistant/helpviewer_qtb.h
@@ -50,7 +50,6 @@
QT_BEGIN_NAMESPACE
-class CentralWidget;
class HelpEngineWrapper;
class QContextMenuEvent;
class QKeyEvent;
@@ -61,7 +60,7 @@ class HelpViewer : public QTextBrowser, public AbstractHelpViewer
Q_OBJECT
public:
- HelpViewer(CentralWidget *parent, qreal zoom = 0.0);
+ HelpViewer(qreal zoom = 0.0);
~HelpViewer();
QFont viewerFont() const;
@@ -79,6 +78,9 @@ public:
inline bool hasSelection() const
{ return textCursor().hasSelection(); }
+signals:
+ void titleChanged();
+
public Q_SLOTS:
void home();
@@ -102,7 +104,6 @@ private:
int zoomCount;
bool controlPressed;
QString lastAnchor;
- CentralWidget* parentWidget;
HelpEngineWrapper &helpEngine;
bool forceFont;
diff --git a/tools/assistant/tools/assistant/helpviewer_qwv.cpp b/tools/assistant/tools/assistant/helpviewer_qwv.cpp
index adaa45b..63816fe 100644
--- a/tools/assistant/tools/assistant/helpviewer_qwv.cpp
+++ b/tools/assistant/tools/assistant/helpviewer_qwv.cpp
@@ -43,6 +43,7 @@
#include "centralwidget.h"
#include "helpenginewrapper.h"
+#include "openpagesmanager.h"
#include "tracer.h"
#include <QtCore/QFileInfo>
@@ -158,7 +159,7 @@ QNetworkReply *HelpNetworkAccessManager::createRequest(Operation /*op*/,
class HelpPage : public QWebPage
{
public:
- HelpPage(CentralWidget *central, QObject *parent);
+ HelpPage(QObject *parent);
protected:
virtual QWebPage *createWindow(QWebPage::WebWindowType);
@@ -168,7 +169,6 @@ protected:
const QNetworkRequest &request, NavigationType type);
private:
- CentralWidget *centralWidget;
bool closeNewTabIfNeeded;
friend class HelpViewer;
@@ -176,9 +176,8 @@ private:
Qt::KeyboardModifiers m_keyboardModifiers;
};
-HelpPage::HelpPage(CentralWidget *central, QObject *parent)
+HelpPage::HelpPage(QObject *parent)
: QWebPage(parent)
- , centralWidget(central)
, closeNewTabIfNeeded(false)
, m_pressedButtons(Qt::NoButton)
, m_keyboardModifiers(Qt::NoModifier)
@@ -189,9 +188,8 @@ HelpPage::HelpPage(CentralWidget *central, QObject *parent)
QWebPage *HelpPage::createWindow(QWebPage::WebWindowType)
{
TRACE_OBJ
- HelpPage* newPage = static_cast<HelpPage*>(centralWidget->newEmptyTab()->page());
- if (newPage)
- newPage->closeNewTabIfNeeded = closeNewTabIfNeeded;
+ HelpPage* newPage = static_cast<HelpPage*>(OpenPagesManager::instance()->createPage()->page());
+ newPage->closeNewTabIfNeeded = closeNewTabIfNeeded;
closeNewTabIfNeeded = false;
return newPage;
}
@@ -218,18 +216,17 @@ bool HelpPage::acceptNavigationRequest(QWebFrame *,
const QUrl &url = request.url();
if (AbstractHelpViewer::launchWithExternalApp(url)) {
if (closeNewTab)
- QMetaObject::invokeMethod(centralWidget, "closeTab");
+ QMetaObject::invokeMethod(OpenPagesManager::instance(), "closeCurrentTab");
return false;
}
if (type == QWebPage::NavigationTypeLinkClicked
&& (m_keyboardModifiers & Qt::ControlModifier
|| m_pressedButtons == Qt::MidButton)) {
- if (centralWidget->newEmptyTab())
- centralWidget->setSource(url);
- m_pressedButtons = Qt::NoButton;
- m_keyboardModifiers = Qt::NoModifier;
- return false;
+ OpenPagesManager::instance()->createPage(url);
+ m_pressedButtons = Qt::NoButton;
+ m_keyboardModifiers = Qt::NoModifier;
+ return false;
}
return true;
@@ -237,23 +234,18 @@ bool HelpPage::acceptNavigationRequest(QWebFrame *,
// -- HelpViewer
-HelpViewer::HelpViewer(CentralWidget *parent, qreal zoom)
- : QWebView(parent)
- , parentWidget(parent)
- , loadFinished(false)
+HelpViewer::HelpViewer(qreal zoom)
+ : loadFinished(false)
, helpEngine(HelpEngineWrapper::instance())
{
TRACE_OBJ
setAcceptDrops(false);
- setPage(new HelpPage(parent, this));
-
+ setPage(new HelpPage(this));
page()->setNetworkAccessManager(new HelpNetworkAccessManager(this));
QAction* action = pageAction(QWebPage::OpenLinkInNewWindow);
action->setText(tr("Open Link in New Tab"));
- if (!parent)
- action->setVisible(false);
pageAction(QWebPage::DownloadLinkToDisk)->setVisible(false);
pageAction(QWebPage::DownloadImageToDisk)->setVisible(false);
@@ -269,6 +261,7 @@ HelpViewer::HelpViewer(CentralWidget *parent, qreal zoom)
SIGNAL(highlighted(QString)));
connect(this, SIGNAL(urlChanged(QUrl)), this, SIGNAL(sourceChanged(QUrl)));
connect(this, SIGNAL(loadFinished(bool)), this, SLOT(setLoadFinished(bool)));
+ connect(this, SIGNAL(titleChanged(QString)), this, SIGNAL(titleChanged()));
setFont(viewerFont());
setTextSizeMultiplier(zoom == 0.0 ? 1.0 : zoom);
diff --git a/tools/assistant/tools/assistant/helpviewer_qwv.h b/tools/assistant/tools/assistant/helpviewer_qwv.h
index a2c0389..92d9e11 100644
--- a/tools/assistant/tools/assistant/helpviewer_qwv.h
+++ b/tools/assistant/tools/assistant/helpviewer_qwv.h
@@ -49,7 +49,6 @@
QT_BEGIN_NAMESPACE
-class CentralWidget;
class HelpEngineWrapper;
class QMouseEvent;
@@ -58,7 +57,7 @@ class HelpViewer : public QWebView, public AbstractHelpViewer
Q_OBJECT
public:
- HelpViewer(CentralWidget *parent, qreal zoom = 0.0);
+ HelpViewer(qreal zoom = 0.0);
~HelpViewer();
QFont viewerFont() const;
@@ -100,6 +99,7 @@ Q_SIGNALS:
void backwardAvailable(bool enabled);
void highlighted(const QString &);
void sourceChanged(const QUrl &);
+ void titleChanged();
protected:
virtual void wheelEvent(QWheelEvent *);
@@ -111,7 +111,6 @@ private Q_SLOTS:
void setLoadFinished(bool ok);
private:
- CentralWidget* parentWidget;
bool loadFinished;
HelpEngineWrapper &helpEngine;
};
diff --git a/tools/assistant/tools/assistant/images/closebutton.png b/tools/assistant/tools/assistant/images/closebutton.png
new file mode 100644
index 0000000..c978cf5
--- /dev/null
+++ b/tools/assistant/tools/assistant/images/closebutton.png
Binary files differ
diff --git a/tools/assistant/tools/assistant/images/darkclosebutton.png b/tools/assistant/tools/assistant/images/darkclosebutton.png
new file mode 100644
index 0000000..1077663
--- /dev/null
+++ b/tools/assistant/tools/assistant/images/darkclosebutton.png
Binary files differ
diff --git a/tools/assistant/tools/assistant/indexwindow.cpp b/tools/assistant/tools/assistant/indexwindow.cpp
index 63ddbe4..7a47e85 100644
--- a/tools/assistant/tools/assistant/indexwindow.cpp
+++ b/tools/assistant/tools/assistant/indexwindow.cpp
@@ -44,6 +44,7 @@
#include "centralwidget.h"
#include "helpenginewrapper.h"
#include "helpviewer.h"
+#include "openpagesmanager.h"
#include "topicchooser.h"
#include <QtGui/QLayout>
@@ -222,7 +223,7 @@ void IndexWindow::open(QHelpIndexWidget* indexWidget, const QModelIndex &index)
if (!AbstractHelpViewer::canOpenPage(url.path()))
CentralWidget::instance()->setSource(url);
else
- CentralWidget::instance()->setSourceInNewTab(url);
+ OpenPagesManager::instance()->createPage(url);
}
}
diff --git a/tools/assistant/tools/assistant/mainwindow.cpp b/tools/assistant/tools/assistant/mainwindow.cpp
index 913e342..9578478 100644
--- a/tools/assistant/tools/assistant/mainwindow.cpp
+++ b/tools/assistant/tools/assistant/mainwindow.cpp
@@ -38,57 +38,55 @@
** $QT_END_LICENSE$
**
****************************************************************************/
-#include "tracer.h"
#include "mainwindow.h"
+#include "aboutdialog.h"
#include "bookmarkmanager.h"
#include "centralwidget.h"
-#include "indexwindow.h"
-#include "topicchooser.h"
+#include "cmdlineparser.h"
#include "contentwindow.h"
-#include "preferencesdialog.h"
+#include "globalactions.h"
#include "helpenginewrapper.h"
+#include "indexwindow.h"
+#include "openpagesmanager.h"
+#include "preferencesdialog.h"
+#include "qtdocinstaller.h"
#include "remotecontrol.h"
-#include "cmdlineparser.h"
-#include "aboutdialog.h"
#include "searchwidget.h"
-#include "qtdocinstaller.h"
-
-// #define TRACING_REQUESTED
+#include "topicchooser.h"
+#include "tracer.h"
-#include <QtCore/QDir>
-#include <QtCore/QTimer>
+#include <QtCore/QByteArray>
#include <QtCore/QDateTime>
#include <QtCore/QDebug>
-#include <QtCore/QFileSystemWatcher>
+#include <QtCore/QDir>
#include <QtCore/QPair>
#include <QtCore/QResource>
-#include <QtCore/QByteArray>
#include <QtCore/QTextStream>
-#include <QtCore/QCoreApplication>
+#include <QtCore/QTimer>
-#include <QtGui/QMenuBar>
#include <QtGui/QAction>
-#include <QtGui/QToolBar>
-#include <QtGui/QStatusBar>
+#include <QtGui/QComboBox>
+#include <QtGui/QDesktopServices>
+#include <QtGui/QDesktopWidget>
+#include <QtGui/QDockWidget>
+#include <QtGui/QFontDatabase>
+#include <QtGui/QFileDialog>
#include <QtGui/QLabel>
-#include <QtGui/QLineEdit>
#include <QtGui/QLayout>
-#include <QtGui/QDockWidget>
-#include <QtGui/QTreeView>
+#include <QtGui/QLineEdit>
+#include <QtGui/QMenuBar>
#include <QtGui/QMessageBox>
-#include <QtGui/QFontDatabase>
-#include <QtGui/QComboBox>
#include <QtGui/QProgressBar>
-#include <QtGui/QDesktopServices>
+#include <QtGui/QStatusBar>
+#include <QtGui/QToolBar>
#include <QtGui/QToolButton>
-#include <QtGui/QFileDialog>
-#include <QtHelp/QHelpEngineCore>
-#include <QtHelp/QHelpSearchEngine>
#include <QtHelp/QHelpContentModel>
+#include <QtHelp/QHelpEngineCore>
#include <QtHelp/QHelpIndexModel>
+#include <QtHelp/QHelpSearchEngine>
QT_BEGIN_NAMESPACE
@@ -105,6 +103,7 @@ MainWindow::MainWindow(CmdLineParser *cmdLine, QWidget *parent)
TRACE_OBJ
setToolButtonStyle(Qt::ToolButtonFollowStyle);
+ setDockOptions(ForceTabbedDocks); // Has no effect; Qt bug?
QString collectionFile;
if (usesDefaultCollection()) {
@@ -131,30 +130,41 @@ MainWindow::MainWindow(CmdLineParser *cmdLine, QWidget *parent)
contentDock->setWidget(m_contentWindow);
addDockWidget(Qt::LeftDockWidgetArea, contentDock);
- QDockWidget *bookmarkDock = 0;
- if (BookmarkManager *manager = BookmarkManager::instance()) {
- bookmarkDock = new QDockWidget(tr("Bookmarks"), this);
- bookmarkDock->setObjectName(QLatin1String("BookmarkWindow"));
- bookmarkDock->setWidget(m_bookmarkWidget = manager->bookmarkDockWidget());
- addDockWidget(Qt::LeftDockWidgetArea, bookmarkDock);
-
- connect(manager, SIGNAL(escapePressed()), this,
+ m_searchWindow = new SearchWidget(helpEngineWrapper.searchEngine());
+ m_searchWindow->setFont(!helpEngineWrapper.usesBrowserFont() ? qApp->font()
+ : helpEngineWrapper.browserFont());
+ QDockWidget *searchDock = new QDockWidget(tr("Search"), this);
+ searchDock->setObjectName(QLatin1String("SearchWindow"));
+ searchDock->setWidget(m_searchWindow);
+ addDockWidget(Qt::LeftDockWidgetArea, searchDock);
+
+ BookmarkManager *bookMarkManager = BookmarkManager::instance();
+ QDockWidget *bookmarkDock = new QDockWidget(tr("Bookmarks"), this);
+ bookmarkDock->setObjectName(QLatin1String("BookmarkWindow"));
+ bookmarkDock->setWidget(m_bookmarkWidget
+ = bookMarkManager->bookmarkDockWidget());
+ addDockWidget(Qt::LeftDockWidgetArea, bookmarkDock);
+
+ QDockWidget *openPagesDock = new QDockWidget(tr("Open Pages"), this);
+ openPagesDock->setObjectName(QLatin1String("Open Pages"));
+ OpenPagesManager *openPagesManager
+ = OpenPagesManager::createInstance(this, usesDefaultCollection(), m_cmdLine->url());
+ openPagesDock->setWidget(openPagesManager->openPagesWidget());
+ addDockWidget(Qt::LeftDockWidgetArea, openPagesDock);
+
+ connect(bookMarkManager, SIGNAL(escapePressed()), this,
SLOT(activateCurrentCentralWidgetTab()));
- connect(manager, SIGNAL(setSource(QUrl)), m_centralWidget,
+ connect(bookMarkManager, SIGNAL(setSource(QUrl)), m_centralWidget,
SLOT(setSource(QUrl)));
- connect(manager, SIGNAL(setSourceInNewTab(QUrl)), m_centralWidget,
- SLOT(setSourceInNewTab(QUrl)));
- connect(m_centralWidget, SIGNAL(addBookmark(QString, QString)), manager,
- SLOT(addBookmark(QString, QString)));
- }
+ connect(bookMarkManager, SIGNAL(setSourceInNewTab(QUrl)),
+ openPagesManager, SLOT(createPage(QUrl)));
+ connect(m_centralWidget, SIGNAL(addBookmark(QString, QString)),
+ bookMarkManager, SLOT(addBookmark(QString, QString)));
QHelpSearchEngine *searchEngine = helpEngineWrapper.searchEngine();
connect(searchEngine, SIGNAL(indexingStarted()), this, SLOT(indexingStarted()));
connect(searchEngine, SIGNAL(indexingFinished()), this, SLOT(indexingFinished()));
- m_centralWidget->createSearchWidget(searchEngine);
- m_centralWidget->activateSearchWidget();
-
QString defWindowTitle = tr("Qt Assistant");
setWindowTitle(defWindowTitle);
@@ -190,10 +200,12 @@ MainWindow::MainWindow(CmdLineParser *cmdLine, QWidget *parent)
restoreGeometry(ba);
} else {
tabifyDockWidget(contentDock, indexDock);
- if (bookmarkDock)
- tabifyDockWidget(indexDock, bookmarkDock);
+ tabifyDockWidget(indexDock, bookmarkDock);
+ tabifyDockWidget(bookmarkDock, openPagesDock);
+ tabifyDockWidget(openPagesDock, searchDock);
contentDock->raise();
- resize(QSize(800, 600));
+ const QRect screen = QApplication::desktop()->screenGeometry();
+ resize(4*screen.width()/5, 4*screen.height()/5);
}
if (!helpEngineWrapper.hasFontSettings()) {
@@ -257,6 +269,8 @@ MainWindow::MainWindow(CmdLineParser *cmdLine, QWidget *parent)
this, SLOT(documentationUpdated(QString)));
}
setTabPosition(Qt::AllDockWidgetAreas, QTabWidget::North);
+ GlobalActions::instance()->updateActions();
+ showNewAddress();
}
MainWindow::~MainWindow()
@@ -387,11 +401,6 @@ void MainWindow::checkInitState()
void MainWindow::insertLastPages()
{
TRACE_OBJ
- if (m_cmdLine->url().isValid())
- m_centralWidget->setSource(m_cmdLine->url());
- else
- m_centralWidget->setupWidget();
-
if (m_cmdLine->search() == CmdLineParser::Activate)
showSearch();
}
@@ -409,8 +418,13 @@ void MainWindow::setupActions()
QMenu *menu = menuBar()->addMenu(tr("&File"));
- m_newTabAction = menu->addAction(tr("New &Tab"), m_centralWidget, SLOT(newTab()));
+ OpenPagesManager * const openPages = OpenPagesManager::instance();
+ m_newTabAction
+ = menu->addAction(tr("New &Tab"), openPages, SLOT(createPage()));
m_newTabAction->setShortcut(QKeySequence::AddTab);
+ m_closeTabAction = menu->addAction(tr("&Close Tab"),
+ openPages, SLOT(closeCurrentPage()));
+ m_closeTabAction->setShortcuts(QKeySequence::Close);
menu->addSeparator();
@@ -419,17 +433,10 @@ void MainWindow::setupActions()
m_printPreviewAction = menu->addAction(tr("Print Preview..."), m_centralWidget,
SLOT(printPreview()));
- m_printAction = menu->addAction(tr("&Print..."), m_centralWidget, SLOT(print()));
- m_printAction->setPriority(QAction::LowPriority);
- m_printAction->setIcon(QIcon(resourcePath + QLatin1String("/print.png")));
- m_printAction->setShortcut(QKeySequence::Print);
-
+ GlobalActions *globalActions = GlobalActions::instance(this);
+ menu->addAction(globalActions->printAction());
menu->addSeparator();
- m_closeTabAction = menu->addAction(tr("&Close Tab"), m_centralWidget,
- SLOT(closeTab()));
- m_closeTabAction->setShortcuts(QKeySequence::Close);
-
QAction *tmp = menu->addAction(QIcon::fromTheme("application-exit"),
tr("&Quit"), this, SLOT(close()));
tmp->setMenuRole(QAction::QuitRole);
@@ -440,19 +447,8 @@ void MainWindow::setupActions()
#endif
menu = menuBar()->addMenu(tr("&Edit"));
- m_copyAction = menu->addAction(tr("&Copy selected Text"), m_centralWidget,
- SLOT(copySelection()));
- m_copyAction->setPriority(QAction::LowPriority);
- m_copyAction->setIconText("&Copy");
- m_copyAction->setIcon(QIcon(resourcePath + QLatin1String("/editcopy.png")));
- m_copyAction->setShortcuts(QKeySequence::Copy);
- m_copyAction->setEnabled(false);
-
- m_findAction = menu->addAction(tr("&Find in Text..."), m_centralWidget,
- SLOT(showTextSearch()));
- m_findAction->setIconText(tr("&Find"));
- m_findAction->setIcon(QIcon(resourcePath + QLatin1String("/find.png")));
- m_findAction->setShortcuts(QKeySequence::Find);
+ menu->addAction(globalActions->copyAction());
+ menu->addAction(globalActions->findAction());
QAction *findNextAction = menu->addAction(tr("Find &Next"), m_centralWidget,
SLOT(findNext()));
@@ -467,17 +463,8 @@ void MainWindow::setupActions()
tmp->setMenuRole(QAction::PreferencesRole);
m_viewMenu = menuBar()->addMenu(tr("&View"));
- m_zoomInAction = m_viewMenu->addAction(tr("Zoom &in"), m_centralWidget,
- SLOT(zoomIn()));
- m_zoomInAction->setPriority(QAction::LowPriority);
- m_zoomInAction->setIcon(QIcon(resourcePath + QLatin1String("/zoomin.png")));
- m_zoomInAction->setShortcut(QKeySequence::ZoomIn);
-
- m_zoomOutAction = m_viewMenu->addAction(tr("Zoom &out"), m_centralWidget,
- SLOT(zoomOut()));
- m_zoomOutAction->setPriority(QAction::LowPriority);
- m_zoomOutAction->setIcon(QIcon(resourcePath + QLatin1String("/zoomout.png")));
- m_zoomOutAction->setShortcut(QKeySequence::ZoomOut);
+ m_viewMenu->addAction(globalActions->zoomInAction());
+ m_viewMenu->addAction(globalActions->zoomOutAction());
m_resetZoomAction = m_viewMenu->addAction(tr("Normal &Size"), m_centralWidget,
SLOT(resetZoom()));
@@ -493,24 +480,15 @@ void MainWindow::setupActions()
QKeySequence(tr("ALT+I")));
m_viewMenu->addAction(tr("Bookmarks"), this, SLOT(showBookmarksDockWidget()),
QKeySequence(tr("ALT+O")));
- m_viewMenu->addAction(tr("Search"), this, SLOT(showSearchWidget()),
+ m_viewMenu->addAction(tr("Search"), this, SLOT(showSearch()),
QKeySequence(tr("ALT+S")));
+ m_viewMenu->addAction(tr("Open Pages"), this, SLOT(showOpenPages()),
+ QKeySequence(tr("ALT+P")));
menu = menuBar()->addMenu(tr("&Go"));
- m_homeAction = menu->addAction(tr("&Home"), m_centralWidget, SLOT(home()));
- m_homeAction->setShortcut(tr("ALT+Home"));
- m_homeAction->setIcon(QIcon(resourcePath + QLatin1String("/home.png")));
-
- m_backAction = menu->addAction(tr("&Back"), m_centralWidget, SLOT(backward()));
- m_backAction->setEnabled(false);
- m_backAction->setShortcuts(QKeySequence::Back);
- m_backAction->setIcon(QIcon(resourcePath + QLatin1String("/previous.png")));
-
- m_nextAction = menu->addAction(tr("&Forward"), m_centralWidget, SLOT(forward()));
- m_nextAction->setPriority(QAction::LowPriority);
- m_nextAction->setEnabled(false);
- m_nextAction->setShortcuts(QKeySequence::Forward);
- m_nextAction->setIcon(QIcon(resourcePath + QLatin1String("/next.png")));
+ menu->addAction(globalActions->homeAction());
+ menu->addAction(globalActions->backAction());
+ menu->addAction(globalActions->nextAction());
m_syncAction = menu->addAction(tr("Sync with Table of Contents"), this,
SLOT(syncContents()));
@@ -519,60 +497,40 @@ void MainWindow::setupActions()
menu->addSeparator();
- tmp = menu->addAction(tr("Next Page"), m_centralWidget, SLOT(nextPage()));
+ tmp = menu->addAction(tr("Next Page"), openPages, SLOT(nextPage()));
tmp->setShortcuts(QList<QKeySequence>() << QKeySequence(tr("Ctrl+Alt+Right"))
<< QKeySequence(Qt::CTRL + Qt::Key_PageDown));
- tmp = menu->addAction(tr("Previous Page"), m_centralWidget, SLOT(previousPage()));
+ tmp = menu->addAction(tr("Previous Page"), openPages, SLOT(previousPage()));
tmp->setShortcuts(QList<QKeySequence>() << QKeySequence(tr("Ctrl+Alt+Left"))
<< QKeySequence(Qt::CTRL + Qt::Key_PageUp));
- if (BookmarkManager *manager = BookmarkManager::instance())
- manager->takeBookmarksMenu(menuBar()->addMenu(tr("&Bookmarks")));
+ BookmarkManager::instance()->takeBookmarksMenu(menuBar()->addMenu(tr("&Bookmarks")));
menu = menuBar()->addMenu(tr("&Help"));
m_aboutAction = menu->addAction(tr("About..."), this, SLOT(showAboutDialog()));
m_aboutAction->setMenuRole(QAction::AboutRole);
#ifdef Q_WS_X11
- m_newTabAction->setIcon(QIcon::fromTheme("tab-new", m_newTabAction->icon()));
- m_closeTabAction->setIcon(QIcon::fromTheme("window-close", m_closeTabAction->icon()));
- m_backAction->setIcon(QIcon::fromTheme("go-previous" , m_backAction->icon()));
- m_nextAction->setIcon(QIcon::fromTheme("go-next" , m_nextAction->icon()));
- m_zoomInAction->setIcon(QIcon::fromTheme("zoom-in" , m_zoomInAction->icon()));
- m_zoomOutAction->setIcon(QIcon::fromTheme("zoom-out" , m_zoomOutAction->icon()));
m_resetZoomAction->setIcon(QIcon::fromTheme("zoom-original" , m_resetZoomAction->icon()));
m_syncAction->setIcon(QIcon::fromTheme("view-refresh" , m_syncAction->icon()));
- m_copyAction->setIcon(QIcon::fromTheme("edit-copy" , m_copyAction->icon()));
- m_findAction->setIcon(QIcon::fromTheme("edit-find" , m_findAction->icon()));
- m_homeAction->setIcon(QIcon::fromTheme("go-home" , m_homeAction->icon()));
- m_pageSetupAction->setIcon(QIcon::fromTheme("document-page-setup", m_pageSetupAction->icon()));
- m_printPreviewAction->setIcon(QIcon::fromTheme("document-print-preview", m_printPreviewAction->icon()));
- m_printAction->setIcon(QIcon::fromTheme("document-print" , m_printAction->icon()));
- m_aboutAction->setIcon(QIcon::fromTheme("help-about", m_aboutAction->icon()));
#endif
QToolBar *navigationBar = addToolBar(tr("Navigation Toolbar"));
navigationBar->setObjectName(QLatin1String("NavigationToolBar"));
- navigationBar->addAction(m_backAction);
- navigationBar->addAction(m_nextAction);
- navigationBar->addAction(m_homeAction);
+ navigationBar->addAction(globalActions->backAction());
+ navigationBar->addAction(globalActions->nextAction());
+ navigationBar->addAction(globalActions->homeAction());
navigationBar->addAction(m_syncAction);
- QAction *sep = navigationBar->addSeparator();
- navigationBar->addAction(m_copyAction);
- navigationBar->addAction(m_printAction);
- navigationBar->addAction(m_findAction);
- QAction *sep2 = navigationBar->addSeparator();
- navigationBar->addAction(m_zoomInAction);
- navigationBar->addAction(m_zoomOutAction);
+ navigationBar->addSeparator();
+ navigationBar->addAction(globalActions->copyAction());
+ navigationBar->addAction(globalActions->printAction());
+ navigationBar->addAction(globalActions->findAction());
+ navigationBar->addSeparator();
+ navigationBar->addAction(globalActions->zoomInAction());
+ navigationBar->addAction(globalActions->zoomOutAction());
navigationBar->addAction(m_resetZoomAction);
- QList<QAction*> actionList;
- actionList << m_backAction << m_nextAction << m_homeAction << sep
- << m_zoomInAction << m_zoomOutAction << sep2 << m_copyAction
- << m_printAction << m_findAction;
- m_centralWidget->setGlobalActions(actionList);
-
#if defined(Q_WS_MAC)
QMenu *windowMenu = new QMenu(tr("&Window"), this);
menuBar()->insertMenu(menu->menuAction(), windowMenu);
@@ -582,16 +540,14 @@ void MainWindow::setupActions()
#endif
// content viewer connections
- connect(m_centralWidget, SIGNAL(copyAvailable(bool)), this,
- SLOT(copyAvailable(bool)));
- connect(m_centralWidget, SIGNAL(currentViewerChanged()), this,
- SLOT(updateNavigationItems()));
- connect(m_centralWidget, SIGNAL(currentViewerChanged()), this,
- SLOT(updateTabCloseAction()));
- connect(m_centralWidget, SIGNAL(forwardAvailable(bool)), this,
- SLOT(updateNavigationItems()));
- connect(m_centralWidget, SIGNAL(backwardAvailable(bool)), this,
- SLOT(updateNavigationItems()));
+ connect(m_centralWidget, SIGNAL(copyAvailable(bool)), globalActions,
+ SLOT(setCopyAvailable(bool)));
+ connect(m_centralWidget, SIGNAL(currentViewerChanged()), globalActions,
+ SLOT(updateActions()));
+ connect(m_centralWidget, SIGNAL(forwardAvailable(bool)), globalActions,
+ SLOT(updateActions()));
+ connect(m_centralWidget, SIGNAL(backwardAvailable(bool)), globalActions,
+ SLOT(updateActions()));
connect(m_centralWidget, SIGNAL(highlighted(QString)), statusBar(),
SLOT(showMessage(QString)));
@@ -609,6 +565,12 @@ void MainWindow::setupActions()
connect(m_contentWindow, SIGNAL(escapePressed()), this,
SLOT(activateCurrentCentralWidgetTab()));
+ // search window
+ connect(m_searchWindow, SIGNAL(requestShowLink(QUrl)),
+ CentralWidget::instance(), SLOT(setSourceFromSearch(QUrl)));
+ connect(m_searchWindow, SIGNAL(requestShowLinkInNewTab(QUrl)),
+ OpenPagesManager::instance(), SLOT(createNewPageFromSearch(QUrl)));
+
#if defined(QT_NO_PRINTER)
m_pageSetupAction->setVisible(false);
m_printPreviewAction->setVisible(false);
@@ -732,26 +694,6 @@ void MainWindow::gotoAddress()
m_centralWidget->setSource(m_addressLineEdit->text());
}
-void MainWindow::updateNavigationItems()
-{
- TRACE_OBJ
- bool hasCurrentViewer = m_centralWidget->isHomeAvailable();
- m_copyAction->setEnabled(m_centralWidget->hasSelection());
- m_homeAction->setEnabled(hasCurrentViewer);
- m_syncAction->setEnabled(hasCurrentViewer);
- m_printPreviewAction->setEnabled(hasCurrentViewer);
- m_printAction->setEnabled(hasCurrentViewer);
- m_nextAction->setEnabled(m_centralWidget->isForwardAvailable());
- m_backAction->setEnabled(m_centralWidget->isBackwardAvailable());
- m_newTabAction->setEnabled(hasCurrentViewer);
-}
-
-void MainWindow::updateTabCloseAction()
-{
- TRACE_OBJ
- m_closeTabAction->setEnabled(m_centralWidget->enableTabCloseAction());
-}
-
void MainWindow::showTopicChooser(const QMap<QString, QUrl> &links,
const QString &keyword)
{
@@ -785,12 +727,6 @@ void MainWindow::syncContents()
qApp->restoreOverrideCursor();
}
-void MainWindow::copyAvailable(bool yes)
-{
- TRACE_OBJ
- m_copyAction->setEnabled(yes);
-}
-
void MainWindow::showAboutDialog()
{
TRACE_OBJ
@@ -899,15 +835,13 @@ void MainWindow::setBookmarksVisible(bool visible)
void MainWindow::showBookmarksDockWidget()
{
TRACE_OBJ
- if (m_bookmarkWidget)
- activateDockWidget(m_bookmarkWidget);
+ activateDockWidget(m_bookmarkWidget);
}
void MainWindow::hideBookmarksDockWidget()
{
TRACE_OBJ
- if (m_bookmarkWidget)
- m_bookmarkWidget->parentWidget()->hide();
+ m_bookmarkWidget->parentWidget()->hide();
}
void MainWindow::setSearchVisible(bool visible)
@@ -922,13 +856,19 @@ void MainWindow::setSearchVisible(bool visible)
void MainWindow::showSearch()
{
TRACE_OBJ
- m_centralWidget->activateSearchWidget();
+ activateDockWidget(m_searchWindow);
+}
+
+void MainWindow::showOpenPages()
+{
+ TRACE_OBJ
+ activateDockWidget(OpenPagesManager::instance()->openPagesWidget());
}
void MainWindow::hideSearch()
{
TRACE_OBJ
- m_centralWidget->removeSearchWidget();
+ m_searchWindow->parentWidget()->hide();
}
void MainWindow::activateDockWidget(QWidget *w)
@@ -948,10 +888,7 @@ void MainWindow::setIndexString(const QString &str)
void MainWindow::activateCurrentBrowser()
{
TRACE_OBJ
- CentralWidget *cw = CentralWidget::instance();
- if (cw) {
- cw->activateTab(true);
- }
+ CentralWidget::instance()->activateTab();
}
void MainWindow::activateCurrentCentralWidgetTab()
@@ -960,12 +897,6 @@ void MainWindow::activateCurrentCentralWidgetTab()
m_centralWidget->activateTab();
}
-void MainWindow::showSearchWidget()
-{
- TRACE_OBJ
- m_centralWidget->activateSearchWidget(true);
-}
-
void MainWindow::updateApplicationFont()
{
TRACE_OBJ
@@ -1087,17 +1018,13 @@ void MainWindow::currentFilterChanged(const QString &filter)
void MainWindow::documentationRemoved(const QString &namespaceName)
{
TRACE_OBJ
- CentralWidget* widget = CentralWidget::instance();
- widget->closeOrReloadTabs(widget->currentSourceFileList().
- keys(namespaceName), false);
+ OpenPagesManager::instance()->closePages(namespaceName);
}
void MainWindow::documentationUpdated(const QString &namespaceName)
{
TRACE_OBJ
- CentralWidget* widget = CentralWidget::instance();
- widget->closeOrReloadTabs(widget->currentSourceFileList().
- keys(namespaceName), true);
+ OpenPagesManager::instance()->reloadPages(namespaceName);
}
void MainWindow::resetQtDocInfo(const QString &component)
diff --git a/tools/assistant/tools/assistant/mainwindow.h b/tools/assistant/tools/assistant/mainwindow.h
index 8e4276d..7eb44e9 100644
--- a/tools/assistant/tools/assistant/mainwindow.h
+++ b/tools/assistant/tools/assistant/mainwindow.h
@@ -42,24 +42,27 @@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
+#include <QtCore/QList>
#include <QtCore/QUrl>
#include <QtGui/QMainWindow>
QT_BEGIN_NAMESPACE
class QAction;
+class QComboBox;
class QFileSystemWatcher;
class QLineEdit;
-class QComboBox;
class QMenu;
-class IndexWindow;
-class QHelpEngineCore;
-class QHelpEngine;
class CentralWidget;
-class ContentWindow;
class CmdLineParser;
+class ContentWindow;
+class IndexWindow;
+class OpenPagesWindow;
class QtDocInstaller;
+class QHelpEngineCore;
+class QHelpEngine;
+class SearchWidget;
class MainWindow : public QMainWindow
{
@@ -87,7 +90,6 @@ public slots:
void setIndexVisible(bool visible);
void setBookmarksVisible(bool visible);
void setSearchVisible(bool visible);
- void showSearchWidget();
void syncContents();
void activateCurrentCentralWidgetTab();
void currentFilterChanged(const QString &filter);
@@ -96,14 +98,12 @@ private slots:
void showContents();
void showIndex();
void showSearch();
+ void showOpenPages();
void insertLastPages();
void gotoAddress();
void showPreferences();
void showNewAddress();
void showAboutDialog();
- void copyAvailable(bool yes);
- void updateNavigationItems();
- void updateTabCloseAction();
void showNewAddress(const QUrl &url);
void showTopicChooser(const QMap<QString, QUrl> &links, const QString &keyword);
void updateApplicationFont();
@@ -144,20 +144,13 @@ private:
CentralWidget *m_centralWidget;
IndexWindow *m_indexWindow;
ContentWindow *m_contentWindow;
+ SearchWidget *m_searchWindow;
QLineEdit *m_addressLineEdit;
QComboBox *m_filterCombo;
- QAction *m_backAction;
- QAction *m_nextAction;
- QAction *m_homeAction;
QAction *m_syncAction;
- QAction *m_copyAction;
- QAction *m_findAction;
- QAction *m_printAction;
QAction *m_printPreviewAction;
QAction *m_pageSetupAction;
- QAction *m_zoomInAction;
- QAction *m_zoomOutAction;
QAction *m_resetZoomAction;
QAction *m_aboutAction;
QAction *m_closeTabAction;
diff --git a/tools/assistant/tools/assistant/openpagesmanager.cpp b/tools/assistant/tools/assistant/openpagesmanager.cpp
new file mode 100644
index 0000000..7a2228f
--- /dev/null
+++ b/tools/assistant/tools/assistant/openpagesmanager.cpp
@@ -0,0 +1,310 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Assistant module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include "openpagesmanager.h"
+
+#include "centralwidget.h"
+#include "helpenginewrapper.h"
+#if defined(QT_NO_WEBKIT)
+#include "helpviewer_qtb.h"
+#else
+#include "helpviewer_qwv.h"
+#endif // QT_NO_WEBKIT
+#include "openpagesmodel.h"
+#include "openpageswidget.h"
+#include "tracer.h"
+#include "../shared/collectionconfiguration.h"
+
+#include <QtGui/QTreeView>
+
+QT_BEGIN_NAMESPACE
+
+OpenPagesManager *OpenPagesManager::createInstance(QObject *parent,
+ bool defaultCollection, const QUrl &cmdLineUrl)
+{
+ TRACE_OBJ
+ Q_ASSERT(!m_instance);
+ m_instance = new OpenPagesManager(parent, defaultCollection, cmdLineUrl);
+ return m_instance;
+}
+
+OpenPagesManager *OpenPagesManager::instance()
+{
+ TRACE_OBJ
+ Q_ASSERT(m_instance);
+ return m_instance;
+}
+
+OpenPagesManager::OpenPagesManager(QObject *parent, bool defaultCollection,
+ const QUrl &cmdLineUrl)
+ : QObject(parent), m_model(new OpenPagesModel(this)),
+ m_openPagesWidget(new OpenPagesWidget(m_model))
+{
+ TRACE_OBJ
+ connect(m_openPagesWidget, SIGNAL(setCurrentPage(QModelIndex)), this,
+ SLOT(setCurrentPage(QModelIndex)));
+ connect(m_openPagesWidget, SIGNAL(closePage(QModelIndex)), this,
+ SLOT(closePage(QModelIndex)));
+ connect(m_openPagesWidget, SIGNAL(closePagesExcept(QModelIndex)), this,
+ SLOT(closePagesExcept(QModelIndex)));
+ setupInitialPages(defaultCollection, cmdLineUrl);
+}
+
+int OpenPagesManager::pageCount() const
+{
+ TRACE_OBJ
+ return m_model->rowCount();
+}
+
+void OpenPagesManager::setupInitialPages(bool defaultCollection,
+ const QUrl &cmdLineUrl)
+{
+ TRACE_OBJ
+ if (cmdLineUrl.isValid()) {
+ createPage(cmdLineUrl);
+ return;
+ }
+
+ HelpEngineWrapper &helpEngine = HelpEngineWrapper::instance();
+ int initialPage = 0;
+ switch (helpEngine.startOption()) {
+ case ShowHomePage:
+ m_model->addPage(helpEngine.homePage());
+ break;
+ case ShowBlankPage:
+ m_model->addPage(QUrl(QLatin1String("about:blank")));
+ break;
+ case ShowLastPages: {
+ const QStringList &lastShownPageList = helpEngine.lastShownPages();
+ const int pageCount = lastShownPageList.count();
+ if (pageCount == 0) {
+ if (defaultCollection)
+ m_model->addPage(QUrl(QLatin1String("help")));
+ else
+ m_model->addPage(QUrl(QLatin1String("about:blank")));
+ } else {
+ QStringList zoomFactors = helpEngine.lastZoomFactors();
+ while (zoomFactors.count() < pageCount)
+ zoomFactors.append(CollectionConfiguration::DefaultZoomFactor);
+ initialPage = helpEngine.lastTabPage();
+ if (initialPage >= pageCount) {
+ qWarning("Initial page set to %d, maximum possible value is %d",
+ initialPage, pageCount - 1);
+ initialPage = 0;
+ }
+ for (int curPage = 0; curPage < pageCount; ++curPage) {
+ const QString &curFile = lastShownPageList.at(curPage);
+ if (helpEngine.findFile(curFile).isValid()
+ || curFile == QLatin1String("about:blank")) {
+ m_model->addPage(curFile, zoomFactors.at(curPage).toFloat());
+ } else if (curPage <= initialPage && initialPage > 0)
+ --initialPage;
+ }
+ }
+ break;
+ }
+ default:
+ Q_ASSERT(!"Unhandled option");
+ }
+
+ if (m_model->rowCount() == 0)
+ m_model->addPage(helpEngine.homePage());
+ for (int i = 0; i < m_model->rowCount(); ++i)
+ CentralWidget::instance()->addPage(m_model->pageAt(i));
+ setCurrentPage(initialPage);
+}
+
+HelpViewer *OpenPagesManager::createPage()
+{
+ TRACE_OBJ
+ return createPage(QUrl(QLatin1String("about:blank")));
+}
+
+void OpenPagesManager::closeCurrentPage()
+{
+ TRACE_OBJ
+ Q_ASSERT(m_model->rowCount() > 1);
+ const QModelIndexList selectedIndexes
+ = m_openPagesWidget->selectionModel()->selectedRows();
+ if (selectedIndexes.isEmpty())
+ return;
+ Q_ASSERT(selectedIndexes.count() == 1);
+ removePage(selectedIndexes.first().row());
+}
+
+HelpViewer *OpenPagesManager::createPage(const QUrl &url, bool fromSearch)
+{
+ TRACE_OBJ
+ if (AbstractHelpViewer::launchWithExternalApp(url))
+ return 0;
+
+ m_model->addPage(url);
+ const int index = m_model->rowCount() - 1;
+ HelpViewer * const page = m_model->pageAt(index);
+ CentralWidget::instance()->addPage(page, fromSearch);
+ setCurrentPage(index);
+ return page;
+}
+
+HelpViewer *OpenPagesManager::createNewPageFromSearch(const QUrl &url)
+{
+ return createPage(url, true);
+}
+
+void OpenPagesManager::closePage(const QModelIndex &index)
+{
+ if (index.isValid())
+ removePage(index.row());
+}
+
+void OpenPagesManager::closePages(const QString &nameSpace)
+{
+ TRACE_OBJ
+ closeOrReloadPages(nameSpace, false);
+}
+
+void OpenPagesManager::reloadPages(const QString &nameSpace)
+{
+ TRACE_OBJ
+ closeOrReloadPages(nameSpace, true);
+ selectCurrentPage();
+}
+
+void OpenPagesManager::closeOrReloadPages(const QString &nameSpace, bool tryReload)
+{
+ TRACE_OBJ
+
+ for (int i = m_model->rowCount() - 1; i >= 0; --i) {
+ HelpViewer *page = m_model->pageAt(i);
+ if (page->source().host() != nameSpace)
+ continue;
+ if (tryReload && HelpEngineWrapper::instance().findFile(page->source()).isValid())
+ page->reload();
+ else if (m_model->rowCount() == 1)
+ page->setSource(QUrl(QLatin1String("about:blank")));
+ else
+ removePage(i);
+ }
+}
+
+bool OpenPagesManager::pagesOpenForNamespace(const QString &nameSpace) const
+{
+ TRACE_OBJ
+ for (int i = 0; i < m_model->rowCount(); ++i)
+ if (m_model->pageAt(i)->source().host() == nameSpace)
+ return true;
+ return false;
+}
+
+void OpenPagesManager::setCurrentPage(const QModelIndex &index)
+{
+ TRACE_OBJ
+ if (!index.isValid())
+ return;
+ HelpViewer * const page = m_model->pageAt(index.row());
+ CentralWidget::instance()->setCurrentPage(page);
+}
+
+void OpenPagesManager::setCurrentPage(int index)
+{
+ TRACE_OBJ
+ CentralWidget::instance()->setCurrentPage(m_model->pageAt(index));
+ selectCurrentPage();
+}
+
+void OpenPagesManager::selectCurrentPage()
+{
+ TRACE_OBJ
+ QItemSelectionModel * const selModel = m_openPagesWidget->selectionModel();
+ selModel->clearSelection();
+ selModel->select(m_model->index(CentralWidget::instance()->currentIndex(), 0),
+ QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
+ m_openPagesWidget->scrollTo(m_openPagesWidget->currentIndex());
+}
+
+void OpenPagesManager::removePage(int index)
+{
+ TRACE_OBJ
+ CentralWidget::instance()->removePage(index);
+ m_model->removePage(index);
+ selectCurrentPage();
+}
+
+
+void OpenPagesManager::closePagesExcept(const QModelIndex &index)
+{
+ TRACE_OBJ
+ if (!index.isValid())
+ return;
+
+ int i = 0;
+ HelpViewer *viewer = m_model->pageAt(index.row());
+ while (m_model->rowCount() > 1) {
+ if (m_model->pageAt(i) != viewer)
+ removePage(i);
+ else
+ ++i;
+ }
+}
+
+QWidget *OpenPagesManager::openPagesWidget() const
+{
+ return m_openPagesWidget;
+}
+
+void OpenPagesManager::nextPage()
+{
+ nextOrPreviousPage(1);
+}
+
+void OpenPagesManager::previousPage()
+{
+ nextOrPreviousPage(-1);
+}
+
+void OpenPagesManager::nextOrPreviousPage(int offset)
+{
+ setCurrentPage((CentralWidget::instance()->currentIndex() + offset
+ + m_model->rowCount()) % m_model->rowCount());
+}
+
+OpenPagesManager *OpenPagesManager::m_instance = 0;
+
+QT_END_NAMESPACE
diff --git a/tools/assistant/tools/assistant/openpagesmanager.h b/tools/assistant/tools/assistant/openpagesmanager.h
new file mode 100644
index 0000000..407ee79
--- /dev/null
+++ b/tools/assistant/tools/assistant/openpagesmanager.h
@@ -0,0 +1,104 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Assistant module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef OPENPAGESMANAGER_H
+#define OPENPAGESMANAGER_H
+
+#include <QtCore/QObject>
+
+QT_BEGIN_NAMESPACE
+
+class QModelIndex;
+class QUrl;
+class QWidget;
+
+class HelpViewer;
+class OpenPagesModel;
+class OpenPagesWidget;
+
+class OpenPagesManager : public QObject
+ {
+ Q_OBJECT
+ public:
+ static OpenPagesManager *createInstance(QObject *parent,
+ bool defaultCollection, const QUrl &cmdLineUrl);
+ static OpenPagesManager *instance();
+
+ bool pagesOpenForNamespace(const QString &nameSpace) const;
+ void closePages(const QString &nameSpace);
+ void reloadPages(const QString &nameSpace);
+
+ QWidget* openPagesWidget() const;
+
+ int pageCount() const;
+
+ public slots:
+ HelpViewer *createPage(const QUrl &url, bool fromSearch = false);
+ HelpViewer *createNewPageFromSearch(const QUrl &url);
+ HelpViewer *createPage();
+ void closeCurrentPage();
+ void nextPage();
+ void previousPage();
+
+private slots:
+ void setCurrentPage(const QModelIndex &index);
+ void closePage(const QModelIndex &index);
+ void closePagesExcept(const QModelIndex &index);
+
+private:
+ OpenPagesManager(QObject *parent, bool defaultCollection,
+ const QUrl &cmdLineUrl);
+ void setupInitialPages(bool defaultCollection, const QUrl &cmdLineUrl);
+ void closeOrReloadPages(const QString &nameSpace, bool tryReload);
+ void setCurrentPage(int index);
+ void selectCurrentPage();
+ void removePage(int index);
+ void nextOrPreviousPage(int offset);
+
+ OpenPagesModel *m_model;
+ OpenPagesWidget *m_openPagesWidget;
+
+ static OpenPagesManager *m_instance;
+ };
+
+QT_END_NAMESPACE
+
+#endif // OPENPAGESMANAGER_H
diff --git a/tools/assistant/tools/assistant/openpagesmodel.cpp b/tools/assistant/tools/assistant/openpagesmodel.cpp
new file mode 100644
index 0000000..92ca1ad
--- /dev/null
+++ b/tools/assistant/tools/assistant/openpagesmodel.cpp
@@ -0,0 +1,123 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Assistant module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include "openpagesmodel.h"
+
+#include "helpenginewrapper.h"
+#if defined(QT_NO_WEBKIT)
+#include "helpviewer_qtb.h"
+#else
+#include "helpviewer_qwv.h"
+#endif // QT_NO_WEBKIT
+#include "tracer.h"
+
+#include <QtCore/QStringList>
+#include <QtCore/QUrl>
+
+QT_BEGIN_NAMESPACE
+
+OpenPagesModel::OpenPagesModel(QObject *parent) : QAbstractTableModel(parent)
+{
+ TRACE_OBJ
+}
+
+int OpenPagesModel::rowCount(const QModelIndex &parent) const
+{
+ TRACE_OBJ
+ return parent.isValid() ? 0 : m_pages.count();
+}
+
+int OpenPagesModel::columnCount(const QModelIndex &/*parent*/) const
+{
+ TRACE_OBJ
+ return 2;
+}
+
+QVariant OpenPagesModel::data(const QModelIndex &index, int role) const
+{
+ TRACE_OBJ
+ if (!index.isValid() || index.row() >= rowCount() || index.column() > 0
+ || role != Qt::DisplayRole)
+ return QVariant();
+ QString title = m_pages.at(index.row())->documentTitle();
+ title.replace(QLatin1Char('&'), QLatin1String("&&"));
+ return title.isEmpty() ? QLatin1String("(Untitled)") : title;
+}
+
+void OpenPagesModel::addPage(const QUrl &url, qreal zoom)
+{
+ TRACE_OBJ
+ beginInsertRows(QModelIndex(), rowCount(), rowCount());
+ HelpViewer *page = new HelpViewer(zoom);
+ connect(page, SIGNAL(titleChanged()), this, SLOT(handleTitleChanged()));
+ m_pages << page;
+ endInsertRows();
+ page->setSource(url);
+}
+
+void OpenPagesModel::removePage(int index)
+{
+ TRACE_OBJ
+ Q_ASSERT(index >= 0 && index < rowCount());
+ beginRemoveRows(QModelIndex(), index, index);
+ HelpViewer *page = m_pages.at(index);
+ m_pages.removeAt(index);
+ endRemoveRows();
+ page->deleteLater();
+}
+
+HelpViewer *OpenPagesModel::pageAt(int index) const
+{
+ TRACE_OBJ
+ Q_ASSERT(index >= 0 && index < rowCount());
+ return m_pages.at(index);
+}
+
+void OpenPagesModel::handleTitleChanged()
+{
+ TRACE_OBJ
+ HelpViewer *page = static_cast<HelpViewer *>(sender());
+ const int row = m_pages.indexOf(page);
+ Q_ASSERT(row != -1 );
+ const QModelIndex &item = index(row, 0);
+ emit dataChanged(item, item);
+}
+
+QT_END_NAMESPACE
diff --git a/tools/assistant/tools/assistant/openpagesmodel.h b/tools/assistant/tools/assistant/openpagesmodel.h
new file mode 100644
index 0000000..64013a6
--- /dev/null
+++ b/tools/assistant/tools/assistant/openpagesmodel.h
@@ -0,0 +1,76 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Assistant module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef OPENPAGESMODEL_H
+#define OPENPAGESMODEL_H
+
+#include <QtCore/QAbstractTableModel>
+#include <QtCore/QList>
+
+QT_BEGIN_NAMESPACE
+
+class HelpViewer;
+class QUrl;
+
+class OpenPagesModel : public QAbstractTableModel
+{
+ Q_OBJECT
+public:
+ OpenPagesModel(QObject *parent);
+
+ virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
+ virtual int columnCount(const QModelIndex &parent = QModelIndex()) const;
+ virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
+
+ void addPage(const QUrl &url, qreal zoom = 0);
+ void removePage(int index);
+ HelpViewer *pageAt(int index) const;
+
+private slots:
+ void handleTitleChanged();
+
+private:
+ QList<HelpViewer *> m_pages;
+};
+
+QT_END_NAMESPACE
+
+#endif // OPENPAGESMODEL_H
diff --git a/tools/assistant/tools/assistant/openpageswidget.cpp b/tools/assistant/tools/assistant/openpageswidget.cpp
new file mode 100644
index 0000000..d702c28
--- /dev/null
+++ b/tools/assistant/tools/assistant/openpageswidget.cpp
@@ -0,0 +1,196 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Assistant module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "openpageswidget.h"
+
+#include "openpagesmodel.h"
+
+#include <QtGui/QApplication>
+#include <QtGui/QHeaderView>
+#include <QtGui/QKeyEvent>
+#include <QtGui/QMouseEvent>
+#include <QtGui/QMenu>
+#include <QtGui/QPainter>
+
+#ifdef Q_WS_MAC
+#include <qmacstyle_mac.h>
+#endif
+
+QT_BEGIN_NAMESPACE
+
+OpenPagesDelegate::OpenPagesDelegate(QObject *parent)
+ : QStyledItemDelegate(parent)
+{
+}
+
+void OpenPagesDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
+ const QModelIndex &index) const
+{
+ if (option.state & QStyle::State_MouseOver) {
+ if ((QApplication::mouseButtons() & Qt::LeftButton) == 0)
+ pressedIndex = QModelIndex();
+ QBrush brush = option.palette.alternateBase();
+ if (index == pressedIndex)
+ brush = option.palette.dark();
+ painter->fillRect(option.rect, brush);
+ }
+
+ QStyledItemDelegate::paint(painter, option, index);
+
+ if (index.column() == 1 && index.model()->rowCount() > 1
+ && option.state & QStyle::State_MouseOver) {
+ QIcon icon((option.state & QStyle::State_Selected)
+ ? ":/trolltech/assistant/images/closebutton.png"
+ : ":/trolltech/assistant/images/darkclosebutton.png");
+
+ const QRect iconRect(option.rect.right() - option.rect.height(),
+ option.rect.top(), option.rect.height(), option.rect.height());
+ icon.paint(painter, iconRect, Qt::AlignRight | Qt::AlignVCenter);
+ }
+}
+
+
+OpenPagesWidget::OpenPagesWidget(OpenPagesModel *model)
+{
+ setModel(model);
+ setIndentation(0);
+ setItemDelegate((m_delegate = new OpenPagesDelegate(this)));
+
+ setFrameStyle(QFrame::NoFrame);
+ setTextElideMode(Qt::ElideMiddle);
+ setAttribute(Qt::WA_MacShowFocusRect, false);
+
+ viewport()->setAttribute(Qt::WA_Hover);
+ setSelectionBehavior(QAbstractItemView::SelectRows);
+ setSelectionMode(QAbstractItemView::SingleSelection);
+
+ header()->hide();
+ header()->setStretchLastSection(false);
+ header()->setResizeMode(0, QHeaderView::Stretch);
+ header()->setResizeMode(1, QHeaderView::Fixed);
+ header()->resizeSection(1, 18);
+
+ installEventFilter(this);
+ setUniformRowHeights(true);
+ setContextMenuPolicy(Qt::CustomContextMenu);
+
+ connect(this, SIGNAL(clicked(QModelIndex)), this,
+ SLOT(handleClicked(QModelIndex)));
+ connect(this, SIGNAL(pressed(QModelIndex)), this,
+ SLOT(handlePressed(QModelIndex)));
+ connect(this, SIGNAL(customContextMenuRequested(QPoint)), this,
+ SLOT(contextMenuRequested(QPoint)));
+}
+
+OpenPagesWidget::~OpenPagesWidget()
+{
+}
+
+void OpenPagesWidget::contextMenuRequested(QPoint pos)
+{
+ QModelIndex index = indexAt(pos);
+ if (!index.isValid())
+ return;
+
+ if (index.column() == 1)
+ index = index.sibling(index.row(), 0);
+ QMenu contextMenu;
+ QAction *closeEditor = contextMenu.addAction(tr("Close %1").arg(index.data()
+ .toString()));
+ QAction *closeOtherEditors = contextMenu.addAction(tr("Close All Except %1")
+ .arg(index.data().toString()));
+
+ if (model()->rowCount() == 1) {
+ closeEditor->setEnabled(false);
+ closeOtherEditors->setEnabled(false);
+ }
+
+ QAction *action = contextMenu.exec(mapToGlobal(pos));
+ if (action == closeEditor)
+ emit closePage(index);
+ else if (action == closeOtherEditors)
+ emit closePagesExcept(index);
+}
+
+void OpenPagesWidget::handlePressed(const QModelIndex &index)
+{
+ if (index.column() == 0)
+ emit setCurrentPage(index);
+
+ if (index.column() == 1)
+ m_delegate->pressedIndex = index;
+}
+
+void OpenPagesWidget::handleClicked(const QModelIndex &index)
+{
+ // implemented here to handle the funky close button and to work around a
+ // bug in item views where the delegate wouldn't get the QStyle::State_MouseOver
+ if (index.column() == 1) {
+ if (model()->rowCount() > 1)
+ emit closePage(index);
+
+ QWidget *vp = viewport();
+ const QPoint &cursorPos = QCursor::pos();
+ QMouseEvent e(QEvent::MouseMove, vp->mapFromGlobal(cursorPos), cursorPos,
+ Qt::NoButton, 0, 0);
+ QCoreApplication::sendEvent(vp, &e);
+ }
+}
+
+bool OpenPagesWidget::eventFilter(QObject *obj, QEvent *event)
+{
+ if (obj == this && event->type() == QEvent::KeyPress) {
+ if (currentIndex().isValid()) {
+ QKeyEvent *ke = static_cast<QKeyEvent*>(event);
+ const int key = ke->key();
+ if ((key == Qt::Key_Return || key == Qt::Key_Enter || key == Qt::Key_Space)
+ && ke->modifiers() == 0) {
+ emit setCurrentPage(currentIndex());
+ } else if ((key == Qt::Key_Delete || key == Qt::Key_Backspace)
+ && ke->modifiers() == 0 && model()->rowCount() > 1) {
+ emit closePage(currentIndex());
+ }
+ }
+ }
+ return QWidget::eventFilter(obj, event);
+}
+
+QT_END_NAMESPACE
diff --git a/tools/assistant/tools/assistant/openpageswidget.h b/tools/assistant/tools/assistant/openpageswidget.h
new file mode 100644
index 0000000..46c0022
--- /dev/null
+++ b/tools/assistant/tools/assistant/openpageswidget.h
@@ -0,0 +1,88 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Assistant module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef OPENPAGESWIDGET_H
+#define OPENPAGESWIDGET_H
+
+#include <QtGui/QStyledItemDelegate>
+#include <QtGui/QTreeView>
+
+QT_BEGIN_NAMESPACE
+
+class OpenPagesModel;
+
+class OpenPagesDelegate : public QStyledItemDelegate
+{
+ Q_OBJECT
+public:
+ explicit OpenPagesDelegate(QObject *parent = 0);
+ void paint(QPainter *painter, const QStyleOptionViewItem &option,
+ const QModelIndex &index) const;
+
+ mutable QModelIndex pressedIndex;
+};
+
+class OpenPagesWidget : public QTreeView
+{
+ Q_OBJECT
+public:
+ OpenPagesWidget(OpenPagesModel *model);
+ ~OpenPagesWidget();
+
+signals:
+ void setCurrentPage(const QModelIndex &index);
+ void closePage(const QModelIndex &index);
+ void closePagesExcept(const QModelIndex &index);
+
+private slots:
+ void contextMenuRequested(QPoint pos);
+ void handlePressed(const QModelIndex &index);
+ void handleClicked(const QModelIndex &index);
+
+private:
+ bool eventFilter(QObject *obj, QEvent *event);
+
+ OpenPagesDelegate *m_delegate;
+};
+
+QT_END_NAMESPACE
+
+#endif // OPENPAGESWIDGET_H
diff --git a/tools/assistant/tools/assistant/preferencesdialog.cpp b/tools/assistant/tools/assistant/preferencesdialog.cpp
index 0e1d719..3535e5a 100644
--- a/tools/assistant/tools/assistant/preferencesdialog.cpp
+++ b/tools/assistant/tools/assistant/preferencesdialog.cpp
@@ -45,6 +45,7 @@
#include "fontpanel.h"
#include "helpenginewrapper.h"
#include "installdialog.h"
+#include "openpagesmanager.h"
#include "tracer.h"
#include <QtCore/QtAlgorithms>
@@ -302,15 +303,12 @@ void PreferencesDialog::addDocumentationLocal()
void PreferencesDialog::removeDocumentation()
{
TRACE_OBJ
- bool foundBefore = false;
- CentralWidget* widget = CentralWidget::instance();
- QMap<int, QString> openedDocList = widget->currentSourceFileList();
- QStringList values(openedDocList.values());
+ bool foundBefore = false;
QList<QListWidgetItem*> l = m_ui.registeredDocsListWidget->selectedItems();
foreach (QListWidgetItem* item, l) {
const QString& ns = item->text();
- if (!foundBefore && values.contains(ns)) {
+ if (!foundBefore && OpenPagesManager::instance()->pagesOpenForNamespace(ns)) {
if (0 == QMessageBox::information(this, tr("Remove Documentation"),
tr("Some documents currently opened in Assistant reference the "
"documentation you are attempting to remove. Removing the "
@@ -320,7 +318,6 @@ void PreferencesDialog::removeDocumentation()
}
m_unregDocs.append(ns);
- m_TabsToClose += openedDocList.keys(ns);
delete m_ui.registeredDocsListWidget->takeItem(
m_ui.registeredDocsListWidget->row(item));
}
@@ -374,10 +371,10 @@ void PreferencesDialog::applyChanges()
}
}
- CentralWidget::instance()->closeOrReloadTabs(m_TabsToClose, false);
-
- foreach (const QString &doc, m_unregDocs)
+ foreach (const QString &doc, m_unregDocs) {
+ OpenPagesManager::instance()->closePages(doc);
helpEngine.unregisterDocumentation(doc);
+ }
if (filtersWereChanged || !m_regDocs.isEmpty() || !m_unregDocs.isEmpty())
helpEngine.setupData();
diff --git a/tools/assistant/tools/assistant/preferencesdialog.h b/tools/assistant/tools/assistant/preferencesdialog.h
index 2894494..7a17275 100644
--- a/tools/assistant/tools/assistant/preferencesdialog.h
+++ b/tools/assistant/tools/assistant/preferencesdialog.h
@@ -96,7 +96,6 @@ private:
QStringList m_docsBackup;
QStringList m_regDocs;
QStringList m_unregDocs;
- QList<int> m_TabsToClose;
FontPanel *m_appFontPanel;
FontPanel *m_browserFontPanel;
bool m_appFontChanged;
diff --git a/tools/assistant/tools/assistant/remotecontrol.cpp b/tools/assistant/tools/assistant/remotecontrol.cpp
index 5ecdd69..06e5602 100644
--- a/tools/assistant/tools/assistant/remotecontrol.cpp
+++ b/tools/assistant/tools/assistant/remotecontrol.cpp
@@ -38,12 +38,13 @@
** $QT_END_LICENSE$
**
****************************************************************************/
-#include "tracer.h"
-
#include "remotecontrol.h"
-#include "mainwindow.h"
+
#include "centralwidget.h"
#include "helpenginewrapper.h"
+#include "mainwindow.h"
+#include "openpagesmanager.h"
+#include "tracer.h"
#include <QtCore/QFile>
#include <QtCore/QFileInfo>
@@ -323,8 +324,7 @@ void RemoteControl::handleUnregisterCommand(const QString &arg)
const QString &absFileName = QFileInfo(arg).absoluteFilePath();
const QString &ns = QHelpEngineCore::namespaceName(absFileName);
if (helpEngine.registeredDocumentations().contains(ns)) {
- CentralWidget* widget = CentralWidget::instance();
- widget->closeOrReloadTabs(widget->currentSourceFileList().keys(ns), false);
+ OpenPagesManager::instance()->closePages(ns);
if (helpEngine.unregisterDocumentation(ns))
helpEngine.setupData();
}