Cpper
C/C++高级工程师 Android高级软件工程师 IT集成工程师 音频工程师 熟悉c,c++,java,c#,py,js,asp等多种语言 程序猿

import QtQuick 2.4
import QtQuick.Controls 1.3
import QtQuick.Window 2.2
import QtQuick.Dialogs 1.2

Rectangle
{
    width
: 640
    height: 450

    ListModel
    {
        id: objmodel
        ListElement
        {
            name: "张飞"
        
}
        ListElement
        
{
            name
: "华佗"
        
}
        ListElement
        
{
            name
: "朱治"
        
}
        ListElement
        
{
            name
: "公孙度"
        
}
        ListElement
        
{
            name
: "袁本初"
        
}
        ListElement
        
{
            name
: "杨松"
        
}
    }

    Component
    
{
        id
: delegateItem
        Item
        {
            id: wrapper
            width: parent.width
            height: 30

            Text
            {
                id: coll
                text: name
                font.pointSize: 13
                color: wrapper.ListView.isCurrentItem? "red":"black"
            
}

            MouseArea
            
{
                id
: mousearea
                anchors.fill: parent
                onClicked:listview.currentIndex = index
;

                onMouseXChanged
:
                {
                    var pore = listview.indexAt(mousearea.mouseX + wrapper.x, mousearea.mouseY + wrapper.y)
;
                    if(index !== pore )
                    {
                        objmodel.move(index,pore,1)
                    
}
                }

                onMouseYChanged:
                
{
                    var pore = listview.indexAt(mousearea.mouseX + wrapper.x, mousearea.mouseY + wrapper.y);
                    if(index !== pore)
                    {
                        objmodel.move(index,pore,1)
                    
}
                }
            }
        }
    }

    ListView
    
{
        id
: listview
        width:240
        height:180
        anchors.centerIn: parent
        delegate: delegateItem
        model:objmodel
        interactive: false
        focus: true

        move: Transition
        {
            NumberAnimation { properties: "x,y"
; duration: 2100 }
        }
    }
}
posted @ 2019-08-30 15:59 ccsdu2009 阅读(1390) | 评论 (0)编辑 收藏
 
import QtQuick 2.11
import QtQuick.Controls 2.4

Rectangle
{
    width
:640
    height:480
    color:"#cfcfc0"

    anchors.margins: 6

    property bool load1: true

    Button
    {
        id:button
        text:"点击加载Loader"
        anchors.horizontalCenter: parent.horizontalCenter
        onClicked:
        {
            if(parent.load1)
            {
                loader.source = "SubRect1.qml"
                parent.load1 = false
            
}
            else
            
{
                loader.source = "SubRect2.qml"
                parent.load1 = true
            
}
        }
    }

    Loader
    
{
        id
:loader
        width: parent.width - 12
        height: parent.height - button.height - 12
        anchors.horizontalCenter: parent.horizontalCenter
        anchors.topMargin: 6
        anchors.top: button.bottom
    
}
}

SubRect1.qml
import QtQuick 2.11
import QtQuick.Controls 2.4

Rectangle
{
    width:480
    height:320
    color:"#0fefc0"

    Component.onCompleted:
    {
        console.log("SubRect1.qml loaded")
    }

    /*Component.onDestroyed:
    {
        console.log("SubRect1.qml onDestroyed")
    }*/

    Component.onDestruction:
    {
        console.log("SubRect1.qml onDestructed")
    }
}

posted @ 2019-08-30 13:39 ccsdu2009 阅读(770) | 评论 (0)编辑 收藏
 
import QtQuick 2.11
import QtQuick.Controls 2.4

Rectangle
{
    width
:640
    height:480
    color:"#cfcfc0"
    DropArea
    {
        id: droparea
        anchors.fill: parent

        property bool hasUrls: false
        enabled: true

        onDropped:
        {
            if(drop.hasUrls)
            {
                var files = drop.urls
                console.log("drop files:",files)
            
}
        }
        onEntered:
        
{
            console.log("extered.")
        
}
    }

}
posted @ 2019-08-29 17:22 ccsdu2009 阅读(452) | 评论 (0)编辑 收藏
 
import QtQuick 2.7
import QtQuick.Controls 2.0
import QtGraphicalEffects 1.0

Rectangle
{
    visible
: true
    width: 400
    height: 300

    Text
    {
        id: textID
        height: 240
        width: 240
        anchors.centerIn: parent
        text:"点击鼠标可旋转文字"
        verticalAlignment: Text.AlignVCenter
        horizontalAlignment: Text.AlignHCenter
        font.pointSize: 13

        MouseArea
        {
            anchors.fill: parent
            onClicked:
            {
                if(rotationAnimation.running === true)
                    return
;
                rotationAnimation.start();
            
}
        }

        LinearGradient
        
{
            source
: textID
            width: 240
            height: 240
            gradient: Gradient
            {
                GradientStop
                {
                    position: 0.0
                    color: "#22F222"
                
}
                GradientStop
                
{
                    position
: 0.9
                    color: "#F0280F"
                
}
            }
            start: Qt.point(0,0)
            end: Qt.point(240,240)
        }
    }

    RotationAnimation
    
{
        id
: rotationAnimation
        target: textID
        from: currentAngle
        to: currentAngle+diff
        duration: 100
        readonly property int diff: 5
        property int currentAngle: 0
        property bool isDown: true

        onStopped:
        {
            rotationAnimation.from = rotationAnimation.to
            rotationAnimation.to = rotationAnimation.to+diff
;
        
}
    }
}
posted @ 2019-08-26 10:03 ccsdu2009 阅读(376) | 评论 (0)编辑 收藏
 
#include <QString>
#include 
<QtPlugin>
#include 
<QObject>

struct AddonInfo
{
    QString name;
    QString description;
    QString version;
    QString author;
};

class AddonInterface : public QObject
{
    Q_OBJECT
public:
    
virtual ~AddonInterface() {}
    
virtual AddonInfo addonInfo()const { return AddonInfo(); }
};

Q_DECLARE_INTERFACE(AddonInterface,
"com.ppx.addon.interface/1.0")

class AddonInterfaceIMPL : public AddonInterface
{
    Q_OBJECT
public:
    AddonInfo addonInfo()
const;

#if QT_VERSION >= 0x050000
    Q_PLUGIN_METADATA(IID 
"com.ppx.addon.interface")
    Q_INTERFACES(AddonInterface);
#endif 
};

#include "addon.h"
#if QT_VERSION < 0x050000
Q_EXPORT_PLUGIN2(FilterInterface,plugin)
#endif // QT_VERSION < 0x050000

AddonInfo AddonInterfaceIMPL::addonInfo()const
{
    AddonInfo addon;
    addon.name = "MyAddOn";
    addon.author = "Coder";
    addon.description = "Description";
    addon.version = "1.0";
    return addon;
}

使用
#include <qplugin.h>
#include <qpluginloader.h>
#include <qdebug>
#include "addon.h"

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    QPluginLoader loader("addon.dll");
    qDebug()<<"load plugin :"<<loader.load();

    auto object = loader.instance();
    qDebug() << "object:" << object;
    if (object)
    {
        AddonInterface* face = qobject_cast<AddonInterface*>(object);
        qDebug() << "face ptr:"<<face;
        auto info = face->addonInfo();
        qDebug() << info.author << " " << info.description << " " << info.name << " " << info.version;
    }

    return a.exec();
}

posted @ 2019-08-23 17:49 ccsdu2009 阅读(199) | 评论 (0)编辑 收藏
 
import QtQuick 2.4

Rectangle
{
    id: dragBackground
    visible: 
true
    color: 
"#dad1db"
    width:
720
    height:
480

    DragRectangle
    {
        z: 
10
        id:dragRectangle
        width: 
480
        height:
240

        Component.onCompleted:
        {
             dragBackground.makeViewCenter(dragRectangle)
        }
    }

    
function makeViewCenter(view)
    {
        
var cx = (width-view.width)*0.5
        
var cy = (height-view.height)*0.5
        view.x 
= cx
        view.y 
= cy
    }
}

Rectangle
import QtQuick 2.0

Rectangle
{
    id:resizeRectangle
    property int enableSize: 12
    property bool isPressed: false
    property point customPoint
    color: "#00debff3"
    border.color: "#d37e49"
    readonly property int minWidth: 64
    readonly property int minHeight: 64

    MouseArea
    {
        id: mouseArea
        anchors.fill: resizeRectangle
        drag.target: parent

        onWheel:
        {
            var diff_w = 0.0
            var diff_h = 0.0

            if(wheel.angleDelta.y > 0)
            {
                diff_w = resizeRectangle.width * 0.02
                diff_h = resizeRectangle.height * 0.02
            }
            else if(wheel.angleDelta.y < 0)
            {
                diff_w = -resizeRectangle.width * 0.02
                diff_h = -resizeRectangle.height * 0.02
            }
            else
            {
                resizeRectangle.width = width
                resizeRectangle.height = height
            }

            fixedRetangle(diff_w,diff_h)

            drag.minimumX = 0
            drag.maximumX = dragBackground.width - resizeRectangle.width
            drag.minimumY = 0
            drag.maximumY = dragBackground.height - resizeRectangle.height
        }
    }

    Item
    {
        id: leftTop
        width: enableSize
        height: enableSize
        anchors.left: parent.left
        anchors.top: parent.top

        MouseArea
        {
            anchors.fill: parent
            hoverEnabled: true

            onPressed: press(mouse)
            onEntered: enter(1)
            onReleased: release()
            onPositionChanged: positionChange(mouse, -1, -1)
        }
    }

    Item
    {
        id: top
        height: enableSize
        anchors.left: leftTop.right
        anchors.right: rightTop.left
        anchors.top: parent.top

        MouseArea
        {
            anchors.fill: parent
            hoverEnabled: true

            onPressed: press(mouse)
            onEntered: enter(2)
            onReleased: release()
            onMouseYChanged: positionChange(Qt.point(customPoint.x, mouseY), 1, -1)
        }
    }

    Item
    {
        id: rightTop
        width: enableSize
        height: enableSize
        anchors.right: parent.right
        anchors.top: parent.top

        MouseArea
        {
            anchors.fill: parent
            hoverEnabled: true

            onPressed: press(mouse)
            onEntered: enter(3)
            onReleased: release()
            onPositionChanged: positionChange(mouse, 1, -1)
        }
    }

    Item
    {
        id: left
        width: enableSize
        anchors.left: parent.left
        anchors.top: leftTop.bottom
        anchors.bottom: leftBottom.top

        MouseArea
        {
            anchors.fill: parent
            hoverEnabled: true

            onPressed: press(mouse)
            onEntered: enter(4)
            onReleased: release()

            onMouseXChanged: positionChange(Qt.point(mouseX, customPoint.y), -1, 1)
        }
    }

    Item
    {
        id: center
        anchors.left: left.right
        anchors.right: right.left
        anchors.top: top.bottom
        anchors.bottom: bottom.top

        MouseArea
        {
            anchors.fill: parent
            property point clickPos

            onPressed: clickPos = Qt.point(mouse.x,mouse.y)
            onPositionChanged:
            {
                if(pressed)
                {
                    var delta = Qt.point(mouse.x-clickPos.x, mouse.y-clickPos.y)
                    resizeRectangle.x += delta.x
                    resizeRectangle.y += delta.y
                    fixedRetangle(0,0)
                }
            }
        }
    }

    Item
    {
        id: right
        width: enableSize
        anchors.right: parent.right
        anchors.top: rightTop.bottom
        anchors.bottom: rightBottom.top

        MouseArea
        {
            anchors.fill: parent
            hoverEnabled: true

            onPressed: press(mouse)
            onEntered: enter(6)
            onReleased: release()
            onMouseXChanged: positionChange(Qt.point(mouseX, customPoint.y), 1, 1)
        }
    }

    Item
    {
        id: leftBottom
        width: enableSize
        height: enableSize
        anchors.left: parent.left
        anchors.bottom: parent.bottom

        MouseArea
        {
            anchors.fill: parent
            hoverEnabled: true

            onPressed: press(mouse)
            onEntered: enter(7)
            onReleased: release()
            onPositionChanged: positionChange(mouse, -1, 1)
        }
    }

    Item
    {
        id: bottom
        height: enableSize
        anchors.left: leftBottom.right
        anchors.right: rightBottom.left
        anchors.bottom: parent.bottom

        MouseArea
        {
            anchors.fill: parent
            hoverEnabled: true

            onPressed: press(mouse)
            onEntered: enter(8)
            onReleased: release()
            onMouseYChanged: positionChange(Qt.point(customPoint.x, mouseY), 1, 1)
        }
    }

    Item
    {
        id:rightBottom
        width: enableSize
        height: enableSize
        anchors.right: parent.right
        anchors.bottom: parent.bottom

        MouseArea
        {
            anchors.fill: parent
            hoverEnabled: true

            onPressed: press(mouse)
            onEntered: enter(9)
            onReleased: release()

            onPositionChanged: positionChange(mouse,1,1)
        }
    }

    function fixedRetangle(dx,dy)
    {
        if(resizeRectangle.width <= minWidth && resizeRectangle.height <= minHeight && dx <=0 && dy <= 0)
            return

        resizeRectangle.x -= dx*0.5
        resizeRectangle.y -= dy*0.5
        resizeRectangle.width += dx
        resizeRectangle.height += dy

        if(resizeRectangle.width < minWidth)
            resizeRectangle.width = minWidth
        if(resizeRectangle.height < minHeight)
            resizeRectangle.height = minHeight

        if(resizeRectangle.width > dragBackground.width)
            resizeRectangle.width = dragBackground.width
        if(resizeRectangle.height > dragBackground.height)
            resizeRectangle.height = dragBackground.height

        if(resizeRectangle.width + resizeRectangle.x > dragBackground.width)
            resizeRectangle.x = dragBackground.width - resizeRectangle.width
        if(resizeRectangle.height + resizeRectangle.y > dragBackground.height)
            resizeRectangle.y = dragBackground.height - resizeRectangle.height

        if(resizeRectangle.y < 0)
            resizeRectangle.y = 0

        if(resizeRectangle.x < 0)
            resizeRectangle.x = 0
    }

    function enter(direct)
    {
    }

    function press(mouse)
    {
        isPressed = true
        customPoint = Qt.point(mouse.x, mouse.y)
    }

    function release()
    {
        isPressed = false
    }

    function positionChange(newPosition,directX, directY)
    {
        if(!isPressed)
            return

        var delta = Qt.point(newPosition.x-customPoint.x, newPosition.y-customPoint.y)
        var tmpW,tmpH

        if(directX >= 0)
            tmpW = resizeRectangle.width + delta.x
        else
            tmpW = resizeRectangle.width - delta.x

        if(directY >= 0)
            tmpH = resizeRectangle.height + delta.y
        else
            tmpH = resizeRectangle.height - delta.y

        if(tmpW < resizeRectangle.minimumWidth)
        {
            if(directX < 0)
                resizeRectangle.x += (resizeRectangle.width - resizeRectangle.minimumWidth)
            resizeRectangle.width = resizeRectangle.minimumWidth
        }
        else
        {
            resizeRectangle.width = tmpW
            if(directX < 0)
                resizeRectangle.x += delta.x
        }

        if(tmpH < resizeRectangle.minimumHeight)
        {
            if(directY < 0)
                resizeRectangle.y += (resizeRectangle.height - resizeRectangle.minimumHeight)
            resizeRectangle.height = resizeRectangle.minimumHeight
        }
        else
        {
            resizeRectangle.height = tmpH
            if(directY < 0)
                resizeRectangle.y += delta.y
        }

        fixedRetangle(0,0)
    }
}

posted @ 2019-08-22 15:00 ccsdu2009 阅读(2153) | 评论 (0)编辑 收藏
 
void adjustImageHSL(QImage& image,qreal hue,qreal saturation,qreal lightness)
{
    unsigned 
int* data = (unsigned int*)image.bits();
    
int size = image.width()*image.height();
    QColor color;

    
for(int i = 0; i < size; i++)
    {
        
int red = qRed(data[i]);
        
int green = qGreen(data[i]);
        
int blue = qBlue(data[i]);
        color.setRed(red);
        color.setGreen(green);
        color.setBlue(blue);
        qreal h 
= color.hueF() + hue;
        qreal s 
= color.saturationF() + saturation;
        qreal l 
= color.lightnessF() + lightness;
        h 
= qBound<qreal>(0,h,1);
        s 
= qBound<qreal>(0,s,1);
        l 
= qBound<qreal>(0,l,1);
        color.setHslF(h,s,l);
        color.setAlpha(qAlpha(data[i]));
        data[i] 
= qRgba(color.red(),color.green(),color.blue(),color.alpha());
    }

    
return;
}
posted @ 2019-08-22 11:49 ccsdu2009 阅读(317) | 评论 (0)编辑 收藏
 
import QtQuick 2.4
import QtQuick.Controls 
2.4
import QtQuick.Layouts 
1.3
import QtQuick.Dialogs 
1.2

Popup
{
    width: 
360
    height: 
90
    modal: 
true
    focus: 
true
    opacity: 
0.96

    
function setWarningText(input)
    {
        warningText.text 
= input
    }

    Text
    {
        id:warningText
        anchors.centerIn: parent
        text: 
"WarningText"
    }
}
posted @ 2019-08-21 15:58 ccsdu2009 阅读(1225) | 评论 (0)编辑 收藏
 
import QtQuick 2.9

Item
{
    visible: 
true
    width: 
1620
    height: 
720
    id:background

    Image
    {
        source: 
"images/2560.png"
        anchors.fill: parent
    }

    Flickable
    {
        id: flick
        anchors.top: parent.top;
        anchors.left: parent.left
        anchors.right: parent.right
        anchors.bottom: parent.bottom
        anchors.margins: 
3
        contentWidth: 
0
        contentHeight: 
0
        clip: 
true

        Image
        {
            id: image
            smooth: 
true
            transformOrigin: Item.Center
            source:
"mark.png"

            onStatusChanged:
            {
                
if(status === Image.Ready)
                {
                    image.width 
*= 0.5
                    image.height 
*= 0.5

                    image.x 
= background.width*0.5-0.5*image.width
                    image.y 
= background.height*0.5-0.5*image.height

                    
/*mouseArea.drag.minimumX = 0
                    mouseArea.drag.maximumX = flick.width - image.width
                    mouseArea.drag.minimumY = 0
                    mouseArea.drag.maximumY = flick.height - image.height
*/
                }
            }
        }
    }

    
function makeImageCenter(imageWidth,imageHeight)
    {
        
var cx = image.x + 0.5*image.width
        
var cy = image.y + 0.5*image.height

        image.width 
= imageWidth
        image.height 
= imageHeight

        image.x 
= cx - image.width*0.5
        image.y 
= cy - image.height*0.5
    }

    MouseArea
    {
        id: mouseArea
        anchors.fill: flick
        drag.target: image

        onWheel:
        {
            
var diff_w = 0.0
            
var diff_h = 0.0

            
if(wheel.angleDelta.y > 0)
            {
                diff_w 
= image.width * 0.02
                diff_h 
= image.height * 0.02
            }
            
else if(wheel.angleDelta.y < 0)
            {
                diff_w 
= -image.width * 0.02
                diff_h 
= -image.height * 0.02
            }
            
else
            {
                image.width 
= width
                image.height 
= height
            }

            
if(wheel.angleDelta.y != 0)
                background.makeImageCenter(image.width
+diff_w,image.height+diff_h)

            drag.minimumX 
= 0
            drag.maximumX 
= flick.width - image.width
            drag.minimumY 
= 0
            drag.maximumY 
= flick.height - image.height
        }
    }
}
posted @ 2019-08-20 13:53 ccsdu2009 阅读(1460) | 评论 (0)编辑 收藏
 
void buildTreeItem(QObjectList* list,QStandardItem* item)
{
    
foreach(auto object,*list)
    {
        auto current 
= new QStandardItem();
        current
->setText(object->objectName());
        item
->appendRow(current);
        auto chidren 
= object->children();
        
if(!chidren.isEmpty())
            buildTreeItem(
&chidren,current);
    }
}

void buildTree(QTreeView* view,const QList<QObject*>& list)
{
    view
->header()->hide();
    view
->setColumnHidden(0,true);
    QStandardItemModel
* model = new QStandardItemModel(view);
    
foreach(auto object,list)
    {
        auto item 
= new QStandardItem(object->objectName());
        auto list 
= object->children();
        buildTreeItem(
&list,item);
        model
->appendRow(item);
    }
    view
->setModel(model);
}

QObject
* buildObjectTree(QObject* parent,const QString& text)
{
    auto 
object = new QObject(parent);
    
object->setObjectName(text);
    
return object;
}



    QWidget widget;
    auto box 
= new QVBoxLayout();
    widget.setLayout(box);
    QTreeView
* tree = new QTreeView(&widget);
    box
->addWidget(tree);

    QList
<QObject*> list;
    auto 
object = buildObjectTree(nullptr,"1");

    list.append(
object);
    
    buildObjectTree(
object"2");
    buildObjectTree(
object"3");
    
object = buildObjectTree(object"4");
    buildObjectTree(
object"5");
    buildObjectTree(
object"6");
    
object = buildObjectTree(object"7");

    buildObjectTree(
object"8");
    buildObjectTree(
object"9");
    buildObjectTree(
object"10");
    buildObjectTree(
object"11");
    
    buildTree(tree,list);
    widget.show();
posted @ 2019-08-19 13:42 ccsdu2009 阅读(221) | 评论 (0)编辑 收藏
仅列出标题
共38页: 1 2 3 4 5 6 7 8 9 Last