Пример #1
0
    def paintEvent(self, theEvent):
        """Custom implementation of the label painter that rotates the
        label 90 degrees.
        """
        pObj = QStylePainter(self)
        oObj = QStyleOptionTab()

        for i in range(self.count()):
            self.initStyleOption(oObj, i)
            pObj.drawControl(QStyle.CE_TabBarTabShape, oObj)
            pObj.save()

            oSize = oObj.rect.size()
            oSize.transpose()
            oRect = QRect(QPoint(), oSize)
            oRect.moveCenter(oObj.rect.center())
            oObj.rect = oRect

            oCenter = self.tabRect(i).center()
            pObj.translate(oCenter)
            pObj.rotate(90)
            pObj.translate(-oCenter)
            pObj.drawControl(QStyle.CE_TabBarTabLabel, oObj)
            pObj.restore()

        return
Пример #2
0
    def __layoutTabs(self):
        self.__layoutDirty = False

        numrows = len(self.__tabList)
        taboverlap = QStyleOptionTab()
        taboverlap.shape = QTabBar.RoundedNorth

        baseoverlap = self.baseOverlap()
        rowoverlap = self.style().pixelMetric(QStyle.PM_TabBarTabShiftVertical,
                                              taboverlap, self)
        rowoverlap += baseoverlap

        maxWidth = 0
        maxHeight = 0
        maxNumTabs = 0
        maxRowWidth = 0
        rowpcts = []

        for i in range(numrows):
            maxNumTabs = max(self.numTabsInRow(i), maxNumTabs)
            mw = 0
            rowpcts.append([])
            for j in range(len(self.__tabList[i])):
                sz = self.tabSizeHint(i, j)
                mw += sz.width()
                maxWidth = max(sz.width(), maxWidth)
                maxHeight = max(maxHeight, sz.height())
                rowpcts[i].append(sz.width())
            rowpcts[i] = [float(x) / mw for x in rowpcts[i]]
            maxRowWidth = max(mw, maxRowWidth)

        maxHeight -= rowoverlap
        centerOffset = 0

        for i in range(numrows):
            x = 0
            if i == self.__selectedIndex[0]:
                y = (len(self.__tabList) - 1) * maxHeight
            elif i < self.__selectedIndex[0] or self.__selectedIndex[0] == -1:
                y = i * maxHeight
            else:
                y = (i - 1) * maxHeight

            for j in range(self.numTabsInRow(i)):
                w = rowpcts[i][j] * maxRowWidth
                if j == self.numTabsInRow(i) - 1 and \
                        (x + int(w)) < maxRowWidth:
                    w = maxRowWidth - x
                self.__tabList[i][j].rect = QRect(x + centerOffset, y, int(w),
                                                  maxHeight + rowoverlap)
                x += int(w)

        self.tabLayoutChange()
Пример #3
0
    def paintEvent(self, event):
        painter = QStylePainter(self)
        opt = QStyleOptionTab()

        for i in range(self.count()):
            self.initStyleOption(opt, i)
            key, name = opt.text.split(':')
            if key in self.mColors:
                opt.text = name
                opt.palette.setColor(QPalette.Button, self.mColors[key])
            painter.drawControl(QStyle.CE_TabBarTabShape, opt)
            painter.drawControl(QStyle.CE_TabBarTabLabel, opt)
Пример #4
0
 def dump(self):
     taboverlap = QStyleOptionTab()
     taboverlap.shape = QTabBar.RoundedNorth
     for var in (
             'PM_TabBarTabOverlap',
             'PM_TabBarTabHSpace',
             'PM_TabBarTabShiftHorizontal',
             'PM_TabBarTabVSpace',
             'PM_TabBarTabShiftVertical',
             'PM_TabBarBaseHeight',
             'PM_TabBarBaseOverlap',
     ):
         val = self.style().pixelMetric(getattr(QStyle, var), taboverlap,
                                        self)
         sys.stdout.write("%s = %s\n" % (var, val))
Пример #5
0
 def paintEvent(self, _e):
     """Override paintEvent to draw the tabs like we want to."""
     p = QStylePainter(self)
     tab = QStyleOptionTab()
     selected = self.currentIndex()
     for idx in range(self.count()):
         self.initStyleOption(tab, idx)
         if idx == selected:
             bg_color = config.get('colors', 'tabs.bg.selected')
             fg_color = config.get('colors', 'tabs.fg.selected')
         elif idx % 2:
             bg_color = config.get('colors', 'tabs.bg.odd')
             fg_color = config.get('colors', 'tabs.fg.odd')
         else:
             bg_color = config.get('colors', 'tabs.bg.even')
             fg_color = config.get('colors', 'tabs.fg.even')
         tab.palette.setColor(QPalette.Window, bg_color)
         tab.palette.setColor(QPalette.WindowText, fg_color)
         indicator_color = self.tabData(idx)
         if indicator_color is None:
             indicator_color = QColor()
         tab.palette.setColor(QPalette.Base, indicator_color)
         if tab.rect.right() < 0 or tab.rect.left() > self.width():
             # Don't bother drawing a tab if the entire tab is outside of
             # the visible tab bar.
             continue
         p.drawControl(QStyle.CE_TabBarTab, tab)
Пример #6
0
    def paintEvent(self, event):
        """Override paintEvent to draw the tabs like we want to."""
        p = QStylePainter(self)
        selected = self.currentIndex()
        for idx in range(self.count()):
            if not event.region().intersects(self.tabRect(idx)):
                # Don't repaint if we are outside the requested region
                continue

            tab = QStyleOptionTab()
            self.initStyleOption(tab, idx)

            setting = 'colors.tabs'
            if self._tab_pinned(idx):
                setting += '.pinned'
            if idx == selected:
                setting += '.selected'
            setting += '.odd' if (idx + 1) % 2 else '.even'

            tab.palette.setColor(QPalette.Window,
                                 config.cache[setting + '.bg'])
            tab.palette.setColor(QPalette.WindowText,
                                 config.cache[setting + '.fg'])

            indicator_color = self.tab_indicator_color(idx)
            tab.palette.setColor(QPalette.Base, indicator_color)
            p.drawControl(QStyle.CE_TabBarTab, tab)
Пример #7
0
    def paintEvent(self, _e):
        """Override paintEvent to draw the tabs like we want to."""
        p = QStylePainter(self)
        selected = self.currentIndex()
        for idx in range(self.count()):
            tab = QStyleOptionTab()
            self.initStyleOption(tab, idx)

            # pylint: disable=bad-config-option
            setting = config.val.colors.tabs
            # pylint: enable=bad-config-option
            if idx == selected:
                setting = setting.selected
            setting = setting.odd if (idx + 1) % 2 else setting.even

            tab.palette.setColor(QPalette.Window, setting.bg)
            tab.palette.setColor(QPalette.WindowText, setting.fg)

            indicator_color = self.tab_indicator_color(idx)
            tab.palette.setColor(QPalette.Base, indicator_color)
            if tab.rect.right() < 0 or tab.rect.left() > self.width():
                # Don't bother drawing a tab if the entire tab is outside of
                # the visible tab bar.
                continue
            p.drawControl(QStyle.CE_TabBarTab, tab)
Пример #8
0
    def paintEvent(self, _e):
        """Override paintEvent to draw the tabs like we want to."""
        # pylint: disable=bad-config-call
        # WORKAROUND for https://bitbucket.org/logilab/astroid/issue/104
        p = QStylePainter(self)
        selected = self.currentIndex()
        for idx in range(self.count()):
            tab = QStyleOptionTab()
            self.initStyleOption(tab, idx)

            bg_parts = ['tabs', 'bg']
            fg_parts = ['tabs', 'fg']
            if idx == selected:
                bg_parts.append('selected')
                fg_parts.append('selected')

            if idx % 2:
                bg_parts.append('odd')
                fg_parts.append('odd')
            else:
                bg_parts.append('even')
                fg_parts.append('even')

            bg_color = config.get('colors', '.'.join(bg_parts))
            fg_color = config.get('colors', '.'.join(fg_parts))
            tab.palette.setColor(QPalette.Window, bg_color)
            tab.palette.setColor(QPalette.WindowText, fg_color)

            indicator_color = self.tab_indicator_color(idx)
            tab.palette.setColor(QPalette.Base, indicator_color)
            if tab.rect.right() < 0 or tab.rect.left() > self.width():
                # Don't bother drawing a tab if the entire tab is outside of
                # the visible tab bar.
                continue
            p.drawControl(QStyle.CE_TabBarTab, tab)
Пример #9
0
    def paintEvent(self, _e):
        """Override paintEvent to draw the tabs like we want to."""
        p = QStylePainter(self)
        selected = self.currentIndex()
        for idx in range(self.count()):
            tab = QStyleOptionTab()
            self.initStyleOption(tab, idx)

            setting = 'colors.tabs'
            if idx == selected:
                setting += '.selected'
            setting += '.odd' if (idx + 1) % 2 else '.even'

            tab.palette.setColor(QPalette.Window,
                                 config.cache[setting + '.bg'])
            tab.palette.setColor(QPalette.WindowText,
                                 config.cache[setting + '.fg'])

            indicator_color = self.tab_indicator_color(idx)
            tab.palette.setColor(QPalette.Base, indicator_color)
            if tab.rect.right() < 0 or tab.rect.left() > self.width():
                # Don't bother drawing a tab if the entire tab is outside of
                # the visible tab bar.
                continue
            p.drawControl(QStyle.CE_TabBarTab, tab)
Пример #10
0
	def paintEvent(self, event):
		painter = QStylePainter(self)
		option = QStyleOptionTab()

		#painter.begin(self)
		for index in range(self.count()):
			self.initStyleOption(option, index)
			tabRect = self.tabRect(index)
			tabRect.moveLeft(10)
			painter.drawControl(QStyle.CE_TabBarTabShape, option)
			painter.drawText(tabRect, Qt.AlignVCenter | Qt.TextDontClip, self.tabText(index))
Пример #11
0
    def paintEvent(self, event):
        painter = QStylePainter(self)
        opt = QStyleOptionTab()

        for i in range(self.count()):
            self.initStyleOption(opt, i)
            painter.drawControl(QStyle.CE_TabBarTabShape, opt)
            painter.save()

            s = opt.rect.size()
            s.transpose()
            r = QRect(QPoint(), s)
            r.moveCenter(opt.rect.center())
            opt.rect = r

            c = self.tabRect(i).center()
            painter.translate(c)
            painter.rotate(270)
            painter.translate(-c)
            painter.drawControl(QStyle.CE_TabBarTabLabel, opt)
            painter.restore()
Пример #12
0
    def paintEvent(self, e):
        tabOverlap = QStyleOptionTab()
        tabOverlap.shape = QTabBar.RoundedNorth
        optTabBase = QStyleOptionTabBarBase()
        optTabBase.initFrom(self)
        optTabBase.shape = QTabBar.RoundedNorth
        optTabBase.tabBarRect = QRect()

        painter = QPainter(self)

        selected = (0, 0)

        for i in range(len(self.__tabList)):
            for j in range(len(self.__tabList[i])):
                tab = self.__getStyleOption(i, j)

                if not (tab.state & QStyle.State_Enabled):
                    tab.palette.setCurrentColorGroup(QPalette.Disabled)

                optTabBase.tabBarRect |= tab.rect

                if (i, j) == self.__selectedIndex:
                    selected = (i, j)
                    optTabBase.selectedTabRect = tab.rect
                    continue

                self.style().drawControl(QStyle.CE_TabBarTab, tab, painter,
                                         self)

        if selected != (-1, -1):
            for j in range(len(self.__tabList[selected[0]])):
                tab = self.__getStyleOption(selected[0], j)
                self.style().drawControl(QStyle.CE_TabBarTab, tab, painter,
                                         self)

            tab = self.__getStyleOption(selected[0], selected[1])
            painter.eraseRect(tab.rect)
            self.style().drawControl(QStyle.CE_TabBarTab, tab, painter, self)
Пример #13
0
 def baseOverlap(self):
     taboverlap = QStyleOptionTab()
     taboverlap.shape = QTabBar.RoundedNorth
     return self.style().pixelMetric(QStyle.PM_TabBarBaseOverlap,
                                     taboverlap, self)
Пример #14
0
    def __getStyleOption(self, row, col):
        tab = self.__tabAt(row, col)
        if not tab: return None

        opt = QStyleOptionTab()
        opt.initFrom(self)
        opt.state &= ~(QStyle.State_HasFocus | QStyle.State_MouseOver)
        opt.rect = self.tabRect(row, col)

        isCurrent = (row, col) == self.__selectedIndex
        opt.row = 0

        if (row, col) == self.__pressedIndex:
            opt.state |= QStyle.State_Sunken
        if isCurrent:
            opt.state |= QStyle.State_Selected
        if isCurrent and self.hasFocus():
            opt.state |= QStyle.State_HasFocus
        if not tab.enabled:
            opt.state &= ~QStyle.State_Enabled
        if self.isActiveWindow():
            opt.state |= QStyle.State_Active
        if opt.rect == self.__hoverRect:
            opt.state |= QStyle.State_MouseOver
        opt.shape = QTabBar.RoundedNorth
        opt.text = tab.text

        if tab.textColor.isValid():
            opt.palette.setColor(self.foregroundRole(), tab.textColor)

        opt.icon = tab.icon
        opt.iconSize = self.iconSize()
        if row == self.__selectedIndex[0]:
            if col > 0 and col - 1 == self.__selectedIndex[1]:
                opt.selectedPosition = QStyleOptionTab.PreviousIsSelected
            elif col < self.numTabsInRow(row) - 1 and \
                    col + 1 == self.__selectedIndex[1]:
                opt.selectedPosition = QStyleOptionTab.NextIsSelected
            else:
                opt.selectedPosition = QStyleOptionTab.NotAdjacent
        else:
            opt.selectedPosition = QStyleOptionTab.NotAdjacent

        if col == 0:
            if self.numTabsInRow(row) > 1:
                opt.position = QStyleOptionTab.Beginning
            else:
                opt.position = QStyleOptionTab.OnlyOneTab
        elif col == self.numTabsInRow(row) - 1:
            opt.position = QStyleOptionTab.End
        else:
            opt.position = QStyleOptionTab.Middle

        return opt