예제 #1
0
    def showExampleSummary(self, uniquename):
        self.newPage()
        self.fadeShapes()
        self.currentExample = uniquename

        horizontalMargin = 0.025 * self.width()
        verticalMargin = 0.025 * self.height()

        title = self.addTitle(self.examples[uniquename]['name'],
                              verticalMargin)
        titleBackground = self.addTitleBackground(title)

        topMargin = 2 * verticalMargin + titleBackground.rect().bottom()
        bottomMargin = self.height() - 8 * verticalMargin
        space = bottomMargin - topMargin
        step = min(title.rect().height() / self.fontRatio,
                   (bottomMargin + 4.8 * verticalMargin - topMargin) /
                   self.maximumLabels)
        footerTextHeight = self.fontRatio * step

        leftMargin = 3 * horizontalMargin
        rightMargin = self.width() - 3 * horizontalMargin

        if self.examples[self.currentExample].has_key('description'):
            description = DocumentShape(
                self.examples[self.currentExample]['description'],
                self.documentFont, QtCore.QPointF(leftMargin, topMargin),
                QtCore.QSizeF(rightMargin - leftMargin, space), 0)
            description.metadata["fade"] = 10

            description.setPosition(
                QtCore.QPointF(
                    description.position().x(),
                    0.8 * self.height() - description.rect().height()))

            self.display.appendShape(description)
            space = description.position().y() - topMargin - 2 * verticalMargin

        if self.examples[self.currentExample].has_key('image files'):
            image = QtGui.QImage(
                self.examples[self.currentExample]['image files'][0])
            imageMaxSize = QtCore.QSizeF(self.width() - 8 * horizontalMargin,
                                         space)

            self.currentFrame = ImageShape(
                image,
                QtCore.QPointF(self.width() - imageMaxSize.width() / 2,
                               topMargin), QtCore.QSizeF(imageMaxSize))

            self.currentFrame.metadata["fade"] = 15
            self.currentFrame.setTarget(
                QtCore.QPointF(self.width() / 2 - imageMaxSize.width() / 2,
                               topMargin))
            self.display.appendShape(self.currentFrame)

            if len(self.examples[self.currentExample]['image files']) > 1:
                self.connect(self.slideshowTimer, QtCore.SIGNAL("timeout()"),
                             self.updateExampleSummary)
                self.slideshowFrame = 0
                self.slideshowTimer.start()

        maxSize = QtCore.QSizeF(0.3 * self.width(), 2 * verticalMargin)
        leftMargin = 0.0
        rightMargin = 0.0

        backButton = TitleShape(
            self.currentCategory, self.font(), QtGui.QPen(QtCore.Qt.white),
            QtCore.QPointF(0.1 * self.width(), self.height()),
            QtCore.QSizeF(maxSize), QtCore.Qt.AlignLeft | QtCore.Qt.AlignTop)
        backButton.setTarget(
            QtCore.QPointF(backButton.position().x(),
                           self.height() - 5.2 * verticalMargin))

        self.display.appendShape(backButton)

        maxWidth = backButton.rect().width()
        textHeight = backButton.rect().height()
        extra = (3 * verticalMargin - textHeight) / 4

        path = QtGui.QPainterPath()
        path.moveTo(-extra, -extra)
        path.lineTo(-4 * extra, textHeight / 2)
        path.lineTo(-extra, textHeight + extra)
        path.lineTo(maxWidth + 2 * extra, textHeight + extra)
        path.lineTo(maxWidth + 2 * extra, -extra)
        path.closeSubpath()

        buttonBackground = PanelShape(
            path, QtGui.QBrush(QtGui.QColor("#a6ce39")),
            QtGui.QBrush(QtGui.QColor("#c7f745")), QtGui.QPen(QtCore.Qt.NoPen),
            QtCore.QPointF(backButton.position()),
            QtCore.QSizeF(maxWidth + 6 * extra, textHeight + 2 * extra))

        buttonBackground.metadata["category"] = self.currentCategory
        buttonBackground.setInteractive(True)
        buttonBackground.setTarget(QtCore.QPointF(backButton.target()))

        self.display.insertShape(0, buttonBackground)

        leftMargin = buttonBackground.rect().right()

        if self.examples[self.currentExample].has_key('absolute path'):
            launchCaption = TitleShape(
                self.tr("Launch"), self.font(), QtGui.QPen(QtCore.Qt.white),
                QtCore.QPointF(0.0, 0.0), QtCore.QSizeF(maxSize),
                QtCore.Qt.AlignLeft | QtCore.Qt.AlignTop)
            launchCaption.setPosition(
                QtCore.QPointF(
                    0.9 * self.width() - launchCaption.rect().width(),
                    self.height()))
            launchCaption.setTarget(
                QtCore.QPointF(launchCaption.position().x(),
                               self.height() - 5.2 * verticalMargin))

            self.display.appendShape(launchCaption)

            maxWidth = launchCaption.rect().width()
            textHeight = launchCaption.rect().height()
            extra = (3 * verticalMargin - textHeight) / 4

            path = QtGui.QPainterPath()
            path.addRect(-2 * extra, -extra, maxWidth + 4 * extra,
                         textHeight + 2 * extra)

            backgroundColor = QtGui.QColor("#a63e39")
            highlightedColor = QtGui.QColor("#f95e56")

            background = PanelShape(
                path, QtGui.QBrush(backgroundColor),
                QtGui.QBrush(highlightedColor), QtGui.QPen(QtCore.Qt.NoPen),
                QtCore.QPointF(launchCaption.position()),
                QtCore.QSizeF(maxWidth + 4 * extra, textHeight + 2 * extra))

            background.metadata["fade minimum"] = 120
            background.metadata["launch"] = self.currentExample
            background.setInteractive(True)
            background.setTarget(QtCore.QPointF(launchCaption.target()))

            if self.currentExample in self.runningExamples:
                background.metadata["highlight"] = True
                background.metadata["highlight scale"] = 0.99
                background.animate()
                background.metadata["fade"] = -135
                self.slideshowTimer.stop()
            self.display.insertShape(0, background)

            rightMargin = background.rect().left()

        if self.examples[self.currentExample]['document path']:

            documentCaption = TitleShape(
                self.tr("Show Documentation"), self.font(),
                QtGui.QPen(QtCore.Qt.white), QtCore.QPointF(0.0, 0.0),
                QtCore.QSizeF(maxSize),
                QtCore.Qt.AlignLeft | QtCore.Qt.AlignTop)

            if rightMargin == 0.0:
                documentCaption.setPosition(
                    QtCore.QPointF(
                        0.9 * self.width() - documentCaption.rect().width(),
                        self.height()))
            else:
                documentCaption.setPosition(
                    QtCore.QPointF(
                        leftMargin / 2 + rightMargin / 2 -
                        documentCaption.rect().width() / 2, self.height()))

            documentCaption.setTarget(
                QtCore.QPointF(documentCaption.position().x(),
                               self.height() - 5.2 * verticalMargin))

            self.display.appendShape(documentCaption)

            maxWidth = documentCaption.rect().width()
            textHeight = documentCaption.rect().height()
            extra = (3 * verticalMargin - textHeight) / 4

            path = QtGui.QPainterPath()
            path.addRect(-2 * extra, -extra, maxWidth + 4 * extra,
                         textHeight + 2 * extra)

            background = PanelShape(
                path, QtGui.QBrush(QtGui.QColor("#9c9cff")),
                QtGui.QBrush(QtGui.QColor("#cfcfff")),
                QtGui.QPen(QtCore.Qt.NoPen),
                QtCore.QPointF(documentCaption.position()),
                QtCore.QSizeF(maxWidth + 4 * extra, textHeight + 2 * extra))

            background.metadata["fade minimum"] = 120
            background.metadata["documentation"] = self.currentExample
            background.setInteractive(True)
            background.setTarget(QtCore.QPointF(documentCaption.target()))

            self.display.insertShape(0, background)

        self.addVersionAndCopyright(
            QtCore.QRectF(2 * horizontalMargin,
                          self.height() - verticalMargin - footerTextHeight,
                          self.width() - 4 * horizontalMargin,
                          footerTextHeight))
예제 #2
0
    def showExamples(self, category):
        self.newPage()
        self.fadeShapes()
        self.currentCategory = category
        self.currentExample = ""

        horizontalMargin = 0.025 * self.width()
        verticalMargin = 0.025 * self.height()

        title = self.addTitle(category, verticalMargin)
        self.addTitleBackground(title)

        topMargin = 6 * verticalMargin
        bottomMargin = self.height() - 3.2 * verticalMargin
        space = bottomMargin - topMargin
        step = min(title.rect().height() / self.fontRatio,
                   space / self.maximumLabels)
        textHeight = self.fontRatio * step

        startPosition = QtCore.QPointF(2 * horizontalMargin,
                                       self.height() + topMargin)
        finishPosition = QtCore.QPointF(2 * horizontalMargin, topMargin)
        maxSize = QtCore.QSizeF(32 * horizontalMargin, textHeight)
        maxWidth = 0.0

        for example in self.categories[self.currentCategory]['examples']:
            caption = TitleShape(example, self.font(), QtGui.QPen(),
                                 QtCore.QPointF(startPosition),
                                 QtCore.QSizeF(maxSize))
            caption.setTarget(QtCore.QPointF(finishPosition))

            self.display.appendShape(caption)

            startPosition += QtCore.QPointF(0.0, step)

            finishPosition += QtCore.QPointF(0.0, step)
            maxWidth = max(maxWidth, caption.rect().width())

        menuButton = TitleShape(self.tr("Main Menu"), self.font(),
                                QtGui.QPen(QtCore.Qt.white),
                                QtCore.QPointF(startPosition),
                                QtCore.QSizeF(maxSize))
        menuButton.setTarget(QtCore.QPointF(finishPosition))
        self.display.appendShape(menuButton)

        startPosition = QtCore.QPointF(self.width(), topMargin)
        extra = (step - textHeight) / 4

        for example in self.categories[self.currentCategory]['examples']:
            uniquename = self.currentCategory + "-" + example

            path = QtGui.QPainterPath()

            path.addRect(-2 * extra, -extra, maxWidth + 4 * extra,
                         textHeight + 2 * extra)

            background = PanelShape(
                path, QtGui.QBrush(self.examples[uniquename]['color']),
                QtGui.QBrush(QtGui.QColor("#e0e0ff")),
                QtGui.QPen(QtCore.Qt.NoPen), QtCore.QPointF(startPosition),
                QtCore.QSizeF(maxWidth + 4 * extra, textHeight + 2 * extra))

            background.metadata["example"] = uniquename
            background.setInteractive(True)
            background.setTarget(
                QtCore.QPointF(2 * horizontalMargin,
                               background.position().y()))
            self.display.insertShape(0, background)
            startPosition += QtCore.QPointF(0.0, step)

        backPath = QtGui.QPainterPath()
        backPath.moveTo(-2 * extra, -extra)
        backPath.lineTo(-8 * extra, textHeight / 2)
        backPath.lineTo(-extra, textHeight + extra)
        backPath.lineTo(maxWidth + 2 * extra, textHeight + extra)
        backPath.lineTo(maxWidth + 2 * extra, -extra)
        backPath.closeSubpath()

        buttonBackground = PanelShape(
            backPath, QtGui.QBrush(QtGui.QColor("#a6ce39")),
            QtGui.QBrush(QtGui.QColor("#c7f745")), QtGui.QPen(QtCore.Qt.NoPen),
            QtCore.QPointF(startPosition),
            QtCore.QSizeF(maxWidth + 10 * extra, textHeight + 2 * extra))

        buttonBackground.metadata["action"] = "parent"
        buttonBackground.setInteractive(True)
        buttonBackground.setTarget(
            QtCore.QPointF(2 * horizontalMargin,
                           buttonBackground.position().y()))
        self.display.insertShape(0, buttonBackground)

        leftMargin = 3 * horizontalMargin + maxWidth
        rightMargin = self.width() - 3 * horizontalMargin

        description = DocumentShape(
            self.categories[self.currentCategory]['description'],
            self.documentFont, QtCore.QPointF(leftMargin, topMargin),
            QtCore.QSizeF(rightMargin - leftMargin, space), 0)

        description.metadata["fade"] = 10
        self.display.appendShape(description)

        self.addVersionAndCopyright(
            QtCore.QRectF(2 * horizontalMargin,
                          self.height() - verticalMargin - textHeight,
                          self.width() - 4 * horizontalMargin, textHeight))
예제 #3
0
    def showCategories(self):
        self.newPage()
        self.fadeShapes()
        self.currentCategory = ""
        self.currentExample = ""

        # Sort the category names excluding any "Qt" prefix.
        def csort(c1, c2):
            if c1.startsWith("Qt "):
                c1 = c1[3:]

            if c2.startsWith("Qt "):
                c2 = c2[3:]

            return cmp(c1, c2)

        categories = [c for c in self.categories.keys() if c != "[main]"]
        categories.sort(csort)

        horizontalMargin = 0.025 * self.width()
        verticalMargin = 0.025 * self.height()
        title = TitleShape(
            self.tr("PyQt Examples and Demos"), self.titleFont,
            QtGui.QPen(QtGui.QColor("#a6ce39")), QtCore.QPointF(),
            QtCore.QSizeF(0.5 * self.width(), 4 * verticalMargin))

        title.setPosition(
            QtCore.QPointF(self.width() / 2 - title.rect().width() / 2,
                           -title.rect().height()))
        title.setTarget(QtCore.QPointF(title.position().x(), verticalMargin))

        self.display.appendShape(title)

        topMargin = 6 * verticalMargin
        bottomMargin = self.height() - 3.2 * verticalMargin
        space = bottomMargin - topMargin
        step = min(title.rect().height() / self.fontRatio,
                   space / self.maximumLabels)
        textHeight = self.fontRatio * step

        startPosition = QtCore.QPointF(0.0, topMargin)
        maxSize = QtCore.QSizeF(10.8 * horizontalMargin, textHeight)
        maxWidth = 0.0

        newShapes = []

        for category in categories:
            caption = TitleShape(category, self.font(), QtGui.QPen(),
                                 QtCore.QPointF(startPosition),
                                 QtCore.QSizeF(maxSize))
            caption.setPosition(
                QtCore.QPointF(-caption.rect().width(),
                               caption.position().y()))
            caption.setTarget(
                QtCore.QPointF(2 * horizontalMargin,
                               caption.position().y()))

            newShapes.append(caption)
            startPosition += QtCore.QPointF(0.0, step)
            maxWidth = max(maxWidth, caption.rect().width())

        exitButton = TitleShape(self.tr("Exit"), self.font(),
                                QtGui.QPen(QtCore.Qt.white),
                                QtCore.QPointF(startPosition),
                                QtCore.QSizeF(maxSize))
        exitButton.setTarget(
            QtCore.QPointF(2 * horizontalMargin,
                           exitButton.position().y()))
        newShapes.append(exitButton)

        startPosition = QtCore.QPointF(self.width(), topMargin)

        extra = (step - textHeight) / 4

        backgroundPath = QtGui.QPainterPath()
        backgroundPath.addRect(-2 * extra, -extra, maxWidth + 4 * extra,
                               textHeight + 2 * extra)

        for category in categories:
            background = PanelShape(
                backgroundPath,
                QtGui.QBrush(self.categories[category]['color']),
                QtGui.QBrush(QtGui.QColor("#e0e0ff")),
                QtGui.QPen(QtCore.Qt.NoPen), QtCore.QPointF(startPosition),
                QtCore.QSizeF(maxWidth + 4 * extra, textHeight + 2 * extra))

            background.metadata["category"] = category
            background.setInteractive(True)
            background.setTarget(
                QtCore.QPointF(2 * horizontalMargin,
                               background.position().y()))
            self.display.insertShape(0, background)
            startPosition += QtCore.QPointF(0.0, step)

        exitPath = QtGui.QPainterPath()
        exitPath.moveTo(-2 * extra, -extra)
        exitPath.lineTo(-8 * extra, textHeight / 2)
        exitPath.lineTo(-extra, textHeight + extra)
        exitPath.lineTo(maxWidth + 2 * extra, textHeight + extra)
        exitPath.lineTo(maxWidth + 2 * extra, -extra)
        exitPath.closeSubpath()

        exitBackground = PanelShape(
            exitPath, QtGui.QBrush(QtGui.QColor("#a6ce39")),
            QtGui.QBrush(QtGui.QColor("#c7f745")), QtGui.QPen(QtCore.Qt.NoPen),
            QtCore.QPointF(startPosition),
            QtCore.QSizeF(maxWidth + 10 * extra, textHeight + 2 * extra))

        exitBackground.metadata["action"] = "exit"
        exitBackground.setInteractive(True)
        exitBackground.setTarget(
            QtCore.QPointF(2 * horizontalMargin,
                           exitBackground.position().y()))
        self.display.insertShape(0, exitBackground)

        for caption in newShapes:
            position = caption.target()
            size = caption.rect().size()
            caption.setPosition(QtCore.QPointF(-maxWidth, position.y()))
            self.display.appendShape(caption)

        leftMargin = 3 * horizontalMargin + maxWidth
        rightMargin = self.width() - 3 * horizontalMargin

        description = DocumentShape(
            self.categories['[main]']['description'], self.documentFont,
            QtCore.QPointF(leftMargin, topMargin),
            QtCore.QSizeF(rightMargin - leftMargin, space))

        description.metadata["fade"] = 10
        self.display.appendShape(description)

        imageHeight = title.rect().height() + verticalMargin

        qtLength = min(imageHeight, title.rect().left() - 3 * horizontalMargin)
        qtMaxSize = QtCore.QSizeF(qtLength, qtLength)

        qtShape = ImageShape(
            self.qtLogo,
            QtCore.QPointF(2 * horizontalMargin - extra, -imageHeight),
            qtMaxSize, 0, QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter)

        qtShape.metadata["fade"] = 15
        qtShape.setTarget(QtCore.QPointF(qtShape.rect().x(), verticalMargin))
        self.display.insertShape(0, qtShape)

        trolltechMaxSize = QtCore.QSizeF(
            self.width() - 3 * horizontalMargin - title.rect().right(),
            imageHeight)

        trolltechShape = ImageShape(
            self.rbLogo,
            QtCore.QPointF(
                self.width() - 2 * horizontalMargin -
                trolltechMaxSize.width() + extra, -imageHeight),
            trolltechMaxSize, 0, QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)

        trolltechShape.metadata["fade"] = 15
        trolltechShape.setTarget(
            QtCore.QPointF(trolltechShape.rect().x(), verticalMargin))

        self.display.insertShape(0, trolltechShape)

        self.addVersionAndCopyright(
            QtCore.QRectF(2 * horizontalMargin,
                          self.height() - verticalMargin - textHeight,
                          self.width() - 4 * horizontalMargin, textHeight))
예제 #4
0
    def showExampleSummary(self, uniquename):
        self.newPage()
        self.fadeShapes()
        self.currentExample = uniquename

        horizontalMargin = 0.025*self.width()
        verticalMargin = 0.025*self.height()

        title = self.addTitle(self.examples[uniquename]['name'], verticalMargin)
        titleBackground = self.addTitleBackground(title)

        topMargin = 2*verticalMargin + titleBackground.rect().bottom()
        bottomMargin = self.height() - 8*verticalMargin
        space = bottomMargin - topMargin
        step = min(title.rect().height() / self.fontRatio,
                    ( bottomMargin + 4.8*verticalMargin - topMargin )/self.maximumLabels )
        footerTextHeight = self.fontRatio * step

        leftMargin = 3*horizontalMargin
        rightMargin = self.width() - 3*horizontalMargin

        if 'description' in self.examples[self.currentExample]:
            description = DocumentShape( self.examples[self.currentExample]['description'],
                                self.documentFont, QtCore.QPointF(leftMargin, topMargin),
                                QtCore.QSizeF(rightMargin-leftMargin, space), 0 )
            description.metadata["fade"] = 10

            description.setPosition(QtCore.QPointF(description.position().x(),
                            0.8*self.height()-description.rect().height()))

            self.display.appendShape(description)
            space = description.position().y() - topMargin - 2*verticalMargin

        if 'image files' in self.examples[self.currentExample]:
            image = QtGui.QImage(self.examples[self.currentExample]['image files'][0])
            imageMaxSize = QtCore.QSizeF(self.width() - 8*horizontalMargin, space)

            self.currentFrame = ImageShape( image,
                            QtCore.QPointF(self.width()-imageMaxSize.width()/2, topMargin),
                            QtCore.QSizeF(imageMaxSize ))

            self.currentFrame.metadata["fade"] = 15
            self.currentFrame.setTarget(QtCore.QPointF(self.width()/2-imageMaxSize.width()/2,
                                    topMargin))
            self.display.appendShape(self.currentFrame)

            if len(self.examples[self.currentExample]['image files']) > 1:
                self.slideshowTimer.timeout.connect(self.updateExampleSummary)
                self.slideshowFrame = 0
                self.slideshowTimer.start()

        maxSize = QtCore.QSizeF(0.3*self.width(),2*verticalMargin)
        leftMargin = 0.0
        rightMargin = 0.0

        backButton = TitleShape(self.currentCategory, self.font(),
            QtGui.QPen(QtCore.Qt.white), QtCore.QPointF(0.1*self.width(), self.height()), QtCore.QSizeF(maxSize),
            QtCore.Qt.AlignLeft | QtCore.Qt.AlignTop)
        backButton.setTarget(QtCore.QPointF(backButton.position().x(),
                                      self.height() - 5.2*verticalMargin))

        self.display.appendShape(backButton)

        maxWidth = backButton.rect().width()
        textHeight = backButton.rect().height()
        extra = (3*verticalMargin - textHeight)/4

        path = QtGui.QPainterPath()
        path.moveTo(-extra, -extra)
        path.lineTo(-4*extra, textHeight/2)
        path.lineTo(-extra, textHeight + extra)
        path.lineTo(maxWidth + 2*extra, textHeight + extra)
        path.lineTo(maxWidth + 2*extra, -extra)
        path.closeSubpath()

        buttonBackground = PanelShape(path,
            QtGui.QBrush(QtGui.QColor("#a6ce39")), QtGui.QBrush(QtGui.QColor("#c7f745")), QtGui.QPen(QtCore.Qt.NoPen),
            QtCore.QPointF(backButton.position()),
            QtCore.QSizeF(maxWidth + 6*extra, textHeight + 2*extra))

        buttonBackground.metadata["category"] =  self.currentCategory
        buttonBackground.setInteractive(True)
        buttonBackground.setTarget(QtCore.QPointF(backButton.target()))

        self.display.insertShape(0, buttonBackground)

        leftMargin = buttonBackground.rect().right()

        if 'absolute path' in self.examples[self.currentExample]:
            launchCaption = TitleShape(self.tr("Launch"),
                self.font(), QtGui.QPen(QtCore.Qt.white), QtCore.QPointF(0.0, 0.0), QtCore.QSizeF(maxSize),
                QtCore.Qt.AlignLeft | QtCore.Qt.AlignTop)
            launchCaption.setPosition(QtCore.QPointF(
                0.9*self.width() - launchCaption.rect().width(), self.height()))
            launchCaption.setTarget(QtCore.QPointF(launchCaption.position().x(),
                                             self.height() - 5.2*verticalMargin))

            self.display.appendShape(launchCaption)

            maxWidth = launchCaption.rect().width()
            textHeight = launchCaption.rect().height()
            extra = (3*verticalMargin - textHeight)/4

            path = QtGui.QPainterPath()
            path.addRect(-2*extra, -extra, maxWidth + 4*extra, textHeight + 2*extra)

            backgroundColor = QtGui.QColor("#a63e39")
            highlightedColor = QtGui.QColor("#f95e56")

            background = PanelShape(path,
                QtGui.QBrush(backgroundColor), QtGui.QBrush(highlightedColor), QtGui.QPen(QtCore.Qt.NoPen),
                QtCore.QPointF(launchCaption.position()),
                QtCore.QSizeF(maxWidth + 4*extra, textHeight + 2*extra))

            background.metadata["fade minimum"] =  120
            background.metadata["launch"] =  self.currentExample
            background.setInteractive(True)
            background.setTarget(QtCore.QPointF(launchCaption.target()))

            if self.currentExample in self.runningExamples:
                background.metadata["highlight"] =  True
                background.metadata["highlight scale"] =  0.99
                background.animate()
                background.metadata["fade"] =  -135
                self.slideshowTimer.stop()
            self.display.insertShape(0, background)

            rightMargin = background.rect().left()

        if self.examples[self.currentExample]['document path']:

            documentCaption = TitleShape(self.tr("Show Documentation"),
                self.font(), QtGui.QPen(QtCore.Qt.white), QtCore.QPointF(0.0, 0.0), QtCore.QSizeF(maxSize),
                QtCore.Qt.AlignLeft | QtCore.Qt.AlignTop)

            if rightMargin == 0.0:
                documentCaption.setPosition(QtCore.QPointF(
                    0.9*self.width() - documentCaption.rect().width(), self.height()))
            else:
                documentCaption.setPosition(QtCore.QPointF(
                    leftMargin/2 + rightMargin/2 - documentCaption.rect().width()/2,
                    self.height()))

            documentCaption.setTarget(QtCore.QPointF(documentCaption.position().x(),
                                               self.height() - 5.2*verticalMargin))

            self.display.appendShape(documentCaption)

            maxWidth = documentCaption.rect().width()
            textHeight = documentCaption.rect().height()
            extra = (3*verticalMargin - textHeight)/4

            path = QtGui.QPainterPath()
            path.addRect(-2*extra, -extra, maxWidth + 4*extra, textHeight + 2*extra)

            background = PanelShape(path,
                QtGui.QBrush(QtGui.QColor("#9c9cff")), QtGui.QBrush(QtGui.QColor("#cfcfff")), QtGui.QPen(QtCore.Qt.NoPen),
                QtCore.QPointF(documentCaption.position()),
                QtCore.QSizeF(maxWidth + 4*extra, textHeight + 2*extra))

            background.metadata["fade minimum"] =  120
            background.metadata["documentation"] =  self.currentExample
            background.setInteractive(True)
            background.setTarget(QtCore.QPointF(documentCaption.target()))

            self.display.insertShape(0, background)

        self.addVersionAndCopyright(QtCore.QRectF(2*horizontalMargin,
                    self.height() - verticalMargin - footerTextHeight,
                    self.width() - 4*horizontalMargin, footerTextHeight))
예제 #5
0
    def showExamples(self, category):
        self.newPage()
        self.fadeShapes()
        self.currentCategory = category
        self.currentExample = ""

        horizontalMargin = 0.025*self.width()
        verticalMargin = 0.025*self.height()

        title = self.addTitle(category, verticalMargin)
        self.addTitleBackground(title)

        topMargin = 6*verticalMargin
        bottomMargin = self.height() - 3.2*verticalMargin
        space = bottomMargin - topMargin
        step = min(title.rect().height() / self.fontRatio, space/self.maximumLabels )
        textHeight = self.fontRatio * step

        startPosition = QtCore.QPointF(2*horizontalMargin, self.height()+topMargin)
        finishPosition = QtCore.QPointF(2*horizontalMargin, topMargin)
        maxSize = QtCore.QSizeF(32*horizontalMargin, textHeight)
        maxWidth = 0.0

        for example in self.categories[self.currentCategory]['examples']:
            caption = TitleShape(example, self.font(), QtGui.QPen(), QtCore.QPointF(startPosition), QtCore.QSizeF(maxSize))
            caption.setTarget(QtCore.QPointF(finishPosition))

            self.display.appendShape(caption)

            startPosition += QtCore.QPointF(0.0, step)

            finishPosition += QtCore.QPointF(0.0, step)
            maxWidth = max(maxWidth, caption.rect().width() )

        menuButton = TitleShape(self.tr("Main Menu"), self.font(),
                                QtGui.QPen(QtCore.Qt.white),
                                QtCore.QPointF(startPosition),
                                QtCore.QSizeF(maxSize))
        menuButton.setTarget(QtCore.QPointF(finishPosition))
        self.display.appendShape(menuButton)

        startPosition = QtCore.QPointF(self.width(), topMargin )
        extra = (step - textHeight)/4

        for example in self.categories[self.currentCategory]['examples']:
            uniquename = self.currentCategory + "-" + example

            path = QtGui.QPainterPath()

            path.addRect(-2*extra, -extra, maxWidth + 4*extra, textHeight+2*extra)

            background = PanelShape(path,
                QtGui.QBrush(self.examples[uniquename]['color']),
                QtGui.QBrush(QtGui.QColor("#e0e0ff")),
                QtGui.QPen(QtCore.Qt.NoPen), QtCore.QPointF(startPosition),
                QtCore.QSizeF(maxWidth + 4*extra, textHeight + 2*extra))

            background.metadata["example"] =  uniquename
            background.setInteractive(True)
            background.setTarget(QtCore.QPointF(2*horizontalMargin,
                                          background.position().y()))
            self.display.insertShape(0, background)
            startPosition += QtCore.QPointF(0.0, step)

        backPath = QtGui.QPainterPath()
        backPath.moveTo(-2*extra, -extra)
        backPath.lineTo(-8*extra, textHeight/2)
        backPath.lineTo(-extra, textHeight + extra)
        backPath.lineTo(maxWidth + 2*extra, textHeight + extra)
        backPath.lineTo(maxWidth + 2*extra, -extra)
        backPath.closeSubpath()

        buttonBackground = PanelShape(backPath,
            QtGui.QBrush(QtGui.QColor("#a6ce39")), QtGui.QBrush(QtGui.QColor("#c7f745")),
            QtGui.QPen(QtCore.Qt.NoPen), QtCore.QPointF(startPosition),
            QtCore.QSizeF(maxWidth + 10*extra, textHeight + 2*extra))

        buttonBackground.metadata["action"] =  "parent"
        buttonBackground.setInteractive(True)
        buttonBackground.setTarget(QtCore.QPointF(2*horizontalMargin,
                                          buttonBackground.position().y()))
        self.display.insertShape(0, buttonBackground)

        leftMargin = 3*horizontalMargin + maxWidth
        rightMargin = self.width() - 3*horizontalMargin

        description = DocumentShape(self.categories[self.currentCategory]['description'],
            self.documentFont, QtCore.QPointF(leftMargin, topMargin),
                QtCore.QSizeF(rightMargin - leftMargin, space), 0)

        description.metadata["fade"] =  10
        self.display.appendShape(description)

        self.addVersionAndCopyright(QtCore.QRectF(2*horizontalMargin,
                    self.height() - verticalMargin - textHeight,
                    self.width() - 4*horizontalMargin, textHeight))
예제 #6
0
    def showCategories(self):
        self.newPage()
        self.fadeShapes()
        self.currentCategory = ""
        self.currentExample = ""

        # Sort the category names excluding any "Qt" prefix.
        def remove_Qt(cat):
            if cat.startsWith("Qt "):
                cat = cat[3:]

            return cat

        categories = [c for c in self.categories.keys() if c != "[main]"]
        categories.sort(key=remove_Qt)

        horizontalMargin = 0.025*self.width()
        verticalMargin = 0.025*self.height()
        title = TitleShape(self.tr("PyQt Examples and Demos"),
                        self.titleFont, QtGui.QPen(QtGui.QColor("#a6ce39")), QtCore.QPointF(),
                        QtCore.QSizeF(0.5*self.width(), 4*verticalMargin))

        title.setPosition(QtCore.QPointF(self.width() / 2 - title.rect().width() / 2,
                                         -title.rect().height()))
        title.setTarget(QtCore.QPointF(title.position().x(), verticalMargin))

        self.display.appendShape(title)

        topMargin = 6*verticalMargin
        bottomMargin = self.height() - 3.2*verticalMargin
        space = bottomMargin - topMargin
        step = min(title.rect().height() / self.fontRatio, space/self.maximumLabels )
        textHeight = self.fontRatio * step

        startPosition = QtCore.QPointF(0.0, topMargin)
        maxSize = QtCore.QSizeF(10.8*horizontalMargin, textHeight)
        maxWidth = 0.0

        newShapes = []

        for category in categories:
            caption = TitleShape(category, self.font(), QtGui.QPen(), QtCore.QPointF(startPosition), QtCore.QSizeF(maxSize))
            caption.setPosition(QtCore.QPointF(-caption.rect().width(),
                                caption.position().y()))
            caption.setTarget(QtCore.QPointF(2*horizontalMargin, caption.position().y()))

            newShapes.append(caption)
            startPosition += QtCore.QPointF(0.0, step)
            maxWidth = max(maxWidth, caption.rect().width() )

        exitButton = TitleShape(self.tr("Exit"), self.font(), QtGui.QPen(QtCore.Qt.white),
                                   QtCore.QPointF(startPosition), QtCore.QSizeF(maxSize))
        exitButton.setTarget(QtCore.QPointF(2*horizontalMargin, exitButton.position().y()))
        newShapes.append(exitButton)

        startPosition = QtCore.QPointF(self.width(), topMargin )

        extra = (step - textHeight)/4

        backgroundPath = QtGui.QPainterPath()
        backgroundPath.addRect(-2*extra, -extra, maxWidth + 4*extra, textHeight + 2*extra)

        for category in categories:
            background = PanelShape(backgroundPath,
                QtGui.QBrush(self.categories[category]['color']), QtGui.QBrush(QtGui.QColor("#e0e0ff")),
                QtGui.QPen(QtCore.Qt.NoPen), QtCore.QPointF(startPosition),
                QtCore.QSizeF(maxWidth + 4*extra, textHeight + 2*extra))

            background.metadata["category"] = category
            background.setInteractive(True)
            background.setTarget(QtCore.QPointF(2*horizontalMargin,
                                          background.position().y()))
            self.display.insertShape(0, background)
            startPosition += QtCore.QPointF(0.0, step)

        exitPath = QtGui.QPainterPath()
        exitPath.moveTo(-2*extra, -extra)
        exitPath.lineTo(-8*extra, textHeight/2)
        exitPath.lineTo(-extra, textHeight + extra)
        exitPath.lineTo(maxWidth + 2*extra, textHeight + extra)
        exitPath.lineTo(maxWidth + 2*extra, -extra)
        exitPath.closeSubpath()

        exitBackground = PanelShape(exitPath,
            QtGui.QBrush(QtGui.QColor("#a6ce39")), QtGui.QBrush(QtGui.QColor("#c7f745")),
            QtGui.QPen(QtCore.Qt.NoPen), QtCore.QPointF(startPosition),
            QtCore.QSizeF(maxWidth + 10*extra, textHeight + 2*extra))

        exitBackground.metadata["action"] = "exit"
        exitBackground.setInteractive(True)
        exitBackground.setTarget(QtCore.QPointF(2*horizontalMargin,
                                          exitBackground.position().y()))
        self.display.insertShape(0, exitBackground)

        for caption in newShapes:
            position = caption.target()
            size = caption.rect().size()
            caption.setPosition(QtCore.QPointF(-maxWidth, position.y()))
            self.display.appendShape(caption)

        leftMargin = 3*horizontalMargin + maxWidth
        rightMargin = self.width() - 3*horizontalMargin

        description = DocumentShape(self.categories['[main]']['description'],
            self.documentFont, QtCore.QPointF(leftMargin, topMargin),
                QtCore.QSizeF(rightMargin - leftMargin, space))

        description.metadata["fade"] = 10
        self.display.appendShape(description)

        imageHeight = title.rect().height() + verticalMargin

        qtLength = min(imageHeight, title.rect().left()-3*horizontalMargin)
        qtMaxSize = QtCore.QSizeF(qtLength, qtLength)

        qtShape = ImageShape(self.qtLogo,
                QtCore.QPointF(2*horizontalMargin-extra, -imageHeight), qtMaxSize, 0,
                QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter)

        qtShape.metadata["fade"] = 15
        qtShape.setTarget(QtCore.QPointF(qtShape.rect().x(), verticalMargin))
        self.display.insertShape(0, qtShape)

        trolltechMaxSize = QtCore.QSizeF(
                self.width()-3*horizontalMargin-title.rect().right(), imageHeight)

        trolltechShape = ImageShape(self.rbLogo,
                QtCore.QPointF(self.width()-2*horizontalMargin-trolltechMaxSize.width()+extra,
                        -imageHeight),
                trolltechMaxSize, 0, QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)

        trolltechShape.metadata["fade"] = 15
        trolltechShape.setTarget(QtCore.QPointF(trolltechShape.rect().x(),
                            verticalMargin))

        self.display.insertShape(0, trolltechShape)

        self.addVersionAndCopyright(QtCore.QRectF(2*horizontalMargin,
                    self.height() - verticalMargin - textHeight,
                    self.width() - 4*horizontalMargin, textHeight))