1
0
Fork 0

Compute scrollbar extent using alternate props

This computation is close enough, and removes the need for private
headers.
This commit is contained in:
James Turner 2018-05-08 22:16:53 +01:00
parent 0da17d895c
commit ee48fddd5e
6 changed files with 9 additions and 142 deletions

View file

@ -342,28 +342,6 @@ if (USE_DBUS)
else()
endif (USE_DBUS)
##############################################################################
function(check_private_headers_exist module private_includes_var)
message(STATUS "Checking whether private include directories for module ${module} exist")
foreach(_dir ${private_includes_var})
if(NOT EXISTS "${_dir}")
message(FATAL_ERROR "The private include directory ${_dir} for module ${module} do not exist! Please make sure your Qt5 installation contains private headers.\nThe required directories:\n ${private_includes_var}")
endif()
endforeach()
endfunction()
function(check_private_header_exists _file _dirs)
set(_found FALSE)
foreach(_dir ${_dirs})
if(EXISTS "${_dir}/${_file}")
set(_found TRUE)
endif()
endforeach()
if(NOT _found)
message(FATAL_ERROR "The private include file ${_file} was not found in directory ${_dirs}! Please make sure your Qt5 installation contains private headers.")
endif()
endfunction()
##############################################################################
## Qt5 setup setup
if (ENABLE_QT)
@ -373,23 +351,6 @@ if (ENABLE_QT)
message(STATUS "Will enable Qt launcher GUI")
message(STATUS " Qt5Widgets version: ${Qt5Widgets_VERSION_STRING}")
message(STATUS " Qt5Widgets include dir: ${Qt5Widgets_INCLUDE_DIRS}")
# copied from KDAB's GammaRay CMakeLists.txt
# Sanity checking, we need private includes for the following modules
check_private_headers_exist("Qt5Gui" "${Qt5Gui_PRIVATE_INCLUDE_DIRS}")
#HACK: CMake with broken Qt5Quick_PRIVATE_INCLUDE_DIRS
if (NOT "${Qt5Quick_PRIVATE_INCLUDE_DIRS}" MATCHES "/QtQuick/")
string(REPLACE "/QtCore" "/QtQuick" replaceme "${Qt5Core_PRIVATE_INCLUDE_DIRS}")
list(APPEND Qt5Quick_PRIVATE_INCLUDE_DIRS ${Qt5Qml_PRIVATE_INCLUDE_DIRS})
list(APPEND Qt5Quick_PRIVATE_INCLUDE_DIRS ${replaceme})
list(REMOVE_DUPLICATES Qt5Quick_PRIVATE_INCLUDE_DIRS)
endif()
check_private_header_exists("private/qquickitem_p.h" "${Qt5Quick_PRIVATE_INCLUDE_DIRS}")
message(STATUS " Qt5Quick private include dir: ${Qt5Quick_PRIVATE_INCLUDE_DIRS}")
set(HAVE_QT 1)
else()
# don't try to build FGQCanvas if Qt wasn't found correctly

View file

@ -148,15 +148,13 @@ if (HAVE_QT)
PreviewImageItem.hxx
ThumbnailImageItem.cxx
ThumbnailImageItem.hxx
FlickableExtentQuery.cxx
FlickableExtentQuery.hxx
PopupWindowTracker.cxx
PopupWindowTracker.hxx
)
set_property(TARGET fgqmlui PROPERTY AUTOMOC ON)
target_link_libraries(fgqmlui Qt5::Quick Qt5::Network Qt5::Qml SimGearCore)
target_include_directories(fgqmlui PRIVATE ${PROJECT_BINARY_DIR}/src/GUI ${Qt5Quick_PRIVATE_INCLUDE_DIRS})
target_include_directories(fgqmlui PRIVATE ${PROJECT_BINARY_DIR}/src/GUI)
endif()

View file

@ -1,46 +0,0 @@
#include "FlickableExtentQuery.hxx"
#include <QtQuick/private/qquickflickable_p.h>
class FriendFlickable : public QQuickFlickable
{
public:
friend class FlickableExtentQuery;
};
FlickableExtentQuery::FlickableExtentQuery(QObject *parent) : QObject(parent)
{
}
qreal FlickableExtentQuery::verticalExtent() const
{
QQuickFlickable* flick = qobject_cast<QQuickFlickable*>(m_flickable);
if (!flick) {
return 0;
}
FriendFlickable* ff = static_cast<FriendFlickable*>(flick);
qreal extent = -ff->maxYExtent() + ff->minYExtent();
return extent;
}
qreal FlickableExtentQuery::minYExtent() const
{
QQuickFlickable* flick = qobject_cast<QQuickFlickable*>(m_flickable);
if (!flick) {
return 0;
}
FriendFlickable* ff = static_cast<FriendFlickable*>(flick);
return ff->minYExtent();
}
void FlickableExtentQuery::setFlickable(QQuickItem *flickable)
{
if (m_flickable == flickable)
return;
m_flickable = flickable;
emit flickableChanged(m_flickable);
}

View file

@ -1,41 +0,0 @@
#ifndef FLICKABLEEXTENTQUERY_HXX
#define FLICKABLEEXTENTQUERY_HXX
#include <QObject>
#include <QQuickItem>
/**
* @brief FlickableExtentQuery exists to expose some unfortunately private
* information from a Flickable, to mimic what QQC2 Scrollbar does internlly.
*/
class FlickableExtentQuery : public QObject
{
Q_OBJECT
Q_PROPERTY(QQuickItem* flickable READ flickable WRITE setFlickable NOTIFY flickableChanged)
public:
explicit FlickableExtentQuery(QObject *parent = nullptr);
QQuickItem* flickable() const
{
return m_flickable;
}
Q_INVOKABLE qreal verticalExtent() const;
Q_INVOKABLE qreal minYExtent() const;
signals:
void flickableChanged(QQuickItem* flickable);
public slots:
void setFlickable(QQuickItem* flickable);
private:
QQuickItem* m_flickable = nullptr;
};
#endif // FLICKABLEEXTENTQUERY_HXX

View file

@ -33,7 +33,6 @@
#include "RecentLocationsModel.hxx"
#include "ThumbnailImageItem.hxx"
#include "PreviewImageItem.hxx"
#include "FlickableExtentQuery.hxx"
#include "MPServersModel.h"
#include "AircraftSearchFilterModel.hxx"
#include "DefaultAircraftLocator.hxx"
@ -101,7 +100,6 @@ void LauncherController::initQML()
qmlRegisterUncreatableType<MPServersModel>("FlightGear.Launcher", 1, 0, "MPServers", "Singleton API");
qmlRegisterType<FileDialogWrapper>("FlightGear.Launcher", 1, 0, "FileDialog");
qmlRegisterType<FlickableExtentQuery>("FlightGear.Launcher", 1, 0, "FlickableExtentQuery");
qmlRegisterType<QmlAircraftInfo>("FlightGear.Launcher", 1, 0, "AircraftInfo");
qmlRegisterType<PopupWindowTracker>("FlightGear.Launcher", 1, 0, "PopupWindowTracker");

View file

@ -1,5 +1,4 @@
import QtQuick 2.4
import FlightGear.Launcher 1.0
Item
{
@ -8,7 +7,6 @@ Item
implicitWidth: 14
property Flickable flickable: parent
readonly property real heightRatio: flickable ? flickable.visibleArea.heightRatio : 0
readonly property int barSize: Math.max(height * heightRatio, width * 3);
@ -24,9 +22,10 @@ Item
return visArea.yPosition / (1.0 - visArea.heightRatio);
}
FlickableExtentQuery {
id: extentQuery
flickable: root.flickable
function verticalExtent()
{
var f = root.flickable;
return (f.height / f.visibleArea.heightRatio) - f.height;
}
MouseArea {
@ -35,8 +34,7 @@ Item
anchors.fill: parent
onClicked: {
var clickPos = (mouse.y / height)
var cy = clickPos * extentQuery.verticalExtent() - extentQuery.minYExtent();
flickable.contentY = cy;
flickable.contentY = clickPos * verticalExtent();
}
visible: root.enabled
}
@ -76,10 +74,9 @@ Item
onMouseYChanged: {
var position = (thumb.y / root.scrollRange)
var cy = position * extentQuery.verticalExtent() - extentQuery.minYExtent();
flickable.contentY = cy;
flickable.contentY = position * verticalExtent();
}
}
}
}
} // of track item
}