2015-07-11 18:56:02 +08:00
|
|
|
/*
|
2022-07-19 19:40:43 +08:00
|
|
|
Copyright (c) 2008-2022 Jan W. Krieger (<jan@jkrieger.de>)
|
2015-07-11 18:56:02 +08:00
|
|
|
|
|
|
|
last modification: $LastChangedDate$ (revision $Rev$)
|
|
|
|
|
|
|
|
This software is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU Lesser General Public License (LGPL) as published by
|
2019-02-08 00:24:46 +08:00
|
|
|
the Free Software Foundation, either version 2.1 of the License, or
|
2015-07-11 18:56:02 +08:00
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU Lesser General Public License (LGPL) for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License (LGPL)
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "jkqttools.h"
|
|
|
|
|
|
|
|
#include <QList>
|
|
|
|
#include <QApplication>
|
|
|
|
#include <QLocale>
|
|
|
|
#include <QtCore>
|
2022-04-23 02:53:54 +08:00
|
|
|
#if (QT_VERSION>QT_VERSION_CHECK(5, 14, 0))
|
2022-04-21 16:57:24 +08:00
|
|
|
# include <QScreen>
|
|
|
|
# include <QGuiApplication>
|
|
|
|
#else
|
|
|
|
# include <QDesktopWidget>
|
|
|
|
#endif
|
2022-04-22 19:27:31 +08:00
|
|
|
#if QT_VERSION>=QT_VERSION_CHECK(6,0,0)
|
|
|
|
# include <QByteArrayView>
|
|
|
|
#endif
|
2015-07-11 18:56:02 +08:00
|
|
|
|
2019-01-26 19:28:44 +08:00
|
|
|
void jksaveWidgetGeometry(QSettings& settings, QWidget* widget, const QString& prefix) {
|
2015-07-11 18:56:02 +08:00
|
|
|
settings.setValue(prefix+"pos", widget->pos());
|
|
|
|
settings.setValue(prefix+"size", widget->size());
|
|
|
|
}
|
|
|
|
|
2019-01-26 19:28:44 +08:00
|
|
|
void jkloadWidgetGeometry(QSettings& settings, QWidget* widget, QPoint defaultPosition, QSize defaultSize, const QString& prefix) {
|
2015-07-11 18:56:02 +08:00
|
|
|
QPoint pos = settings.value(prefix+"pos", defaultPosition).toPoint();
|
2022-04-21 16:57:24 +08:00
|
|
|
const QSize size = settings.value(prefix+"size", defaultSize).toSize();
|
2022-04-23 02:53:54 +08:00
|
|
|
#if (QT_VERSION>=QT_VERSION_CHECK(5, 14, 0))
|
2022-04-21 16:57:24 +08:00
|
|
|
const auto widgeo = widget->screen()->geometry();
|
|
|
|
#else
|
|
|
|
const auto widgeo = QApplication::desktop()->screenGeometry(widget);
|
|
|
|
#endif
|
|
|
|
widget->resize(size.boundedTo(widgeo.size()));
|
|
|
|
if (pos.x()<0 || pos.x()>widgeo.width()) pos.setX(0);
|
|
|
|
if (pos.y()<0 || pos.y()>widgeo.height()) pos.setY(0);
|
2015-07-11 18:56:02 +08:00
|
|
|
widget->move(pos);
|
|
|
|
}
|
|
|
|
|
2019-01-26 19:28:44 +08:00
|
|
|
void jkloadWidgetGeometry(QSettings& settings, QWidget* widget, const QString& prefix) {
|
2015-07-11 18:56:02 +08:00
|
|
|
jkloadWidgetGeometry(settings, widget, QPoint(10, 10), QSize(100, 100), prefix);
|
|
|
|
}
|
|
|
|
|
2019-01-26 19:28:44 +08:00
|
|
|
void jksaveSplitter(QSettings& settings, QSplitter* splitter, const QString& prefix) {
|
2015-07-11 18:56:02 +08:00
|
|
|
/*QList<int> sizes=splitter->sizes();
|
|
|
|
QString data="";
|
|
|
|
for (int i=0; i<sizes.size(); i++) {
|
|
|
|
if (!data.isEmpty()) data=data+",";
|
|
|
|
data=data+QLocale::system().toString(sizes[i]);
|
|
|
|
}
|
|
|
|
settings.setValue(prefix+"splitter_sizes", data);*/
|
|
|
|
settings.setValue(prefix+"splitter_sizes", splitter->saveState());
|
|
|
|
}
|
|
|
|
|
2019-01-26 19:28:44 +08:00
|
|
|
void jkloadSplitter(QSettings& settings, QSplitter* splitter, const QString& prefix) {
|
2015-07-11 18:56:02 +08:00
|
|
|
/*QString data=settings.value(prefix+"splitter_sizes", "").toString();
|
|
|
|
QList<int> sizes, s1;
|
|
|
|
QStringList sl=data.split(",");
|
|
|
|
for (int i=0; i<sl.size(); i++) {
|
|
|
|
sizes.append(sl[i].toInt());
|
|
|
|
}
|
|
|
|
s1=splitter->sizes();
|
|
|
|
for (int i=0; i<s1.count(); i++) {
|
|
|
|
if (i<sizes.size()) s1[i]=sizes[i];
|
|
|
|
}*/
|
|
|
|
splitter->restoreState(settings.value(prefix+"splitter_sizes").toByteArray());
|
|
|
|
}
|
|
|
|
|
2022-04-22 19:27:31 +08:00
|
|
|
quint16 jkqtp_checksum(const void *data, size_t len)
|
|
|
|
{
|
|
|
|
#if QT_VERSION>=QT_VERSION_CHECK(6,0,0)
|
|
|
|
return qChecksum(QByteArrayView(static_cast<const uint8_t*>(data), len));
|
|
|
|
#else
|
2022-04-22 19:32:24 +08:00
|
|
|
return qChecksum(static_cast<const char*>(data), len);
|
2022-04-22 19:27:31 +08:00
|
|
|
#endif
|
|
|
|
}
|