Ejemplo n.º 1
0
 def restoreData(self):
     '''
     @return: QJsonArray
     '''
     out = []
     idx = 0
     for window in self._manager.restoreData().windows:
         jdx = 0
         tabs = []
         for tab in window.tabs:
             icon = tab.icon.isNull() and IconProvider.emptyWebIcon(
             ) or tab.icon
             item = {}
             item['tab'] = jdx
             item['icon'] = gVar.appTools.pixmapToDataUrl(icon.pixmap(16))
             item['title'] = tab.title
             item['url'] = tab.url.toString()
             item['pinned'] = tab.isPinned
             item['current'] = window.currentTab == jdx
             tabs.append(item)
             jdx += 1
         window = {}
         window['window'] = idx
         idx += 1
         window['tabs'] = tabs
         out.append(window)
     return out
Ejemplo n.º 2
0
 def _updateSiteIcon(self):
     if self._completer.isVisible():
         self._siteIcon.setIcon(
             QIcon.fromTheme('edit-find',
                             QIcon(':/icons/menu/search-icon.svg')))
     else:
         icon = IconProvider.emptyWebIcon()
         secured = self.property('secured')
         if secured:
             icon = QIcon.fromTheme('document-encrypted', icon)
         self._siteIcon.setIcon(icon.pixmap(16))
 def addCompletions(self, items):
     '''
     @param: items QList<QStandardItem>
     '''
     for item in items:
         img = item.data(self.ImageRole)
         if not img:
             img = QImage()
         pixmap = QPixmap.fromImage(img)
         item.setIcon(QIcon(pixmap))
         self._setTabPosition(item)
         if item.icon().isNull():
             item.setIcon(IconProvider.emptyWebIcon())
         self.appendRow([item])
Ejemplo n.º 4
0
    def paintEvent(self, event):
        '''
        @param event QPaintEvent
        '''
        p = QPainter(self)
        p.setRenderHint(QPainter.Antialiasing)

        size = 16
        pixmapSize = round(size *
                           self.data().animationPixmap.devicePixelRatioF())

        # Center the pixmap in rect
        r = QRect(self.rect())
        r.setX((r.width() - size) / 2)
        r.setY((r.height() - size) / 2)
        r.setWidth(size)
        r.setHeight(size)

        if self._animationRunning:
            p.drawPixmap(
                r,
                self.data().animationPixmap,
                QRect(self._currentFrame * pixmapSize, 0, pixmapSize,
                      pixmapSize))
        elif self._audioIconDisplayed and not self._tab.isPinned():
            self._audioIconRect = QRect(r)
            p.drawPixmap(
                r,
                self._tab.isMuted() and self.data().audioMutedPixmap
                or self.data().audioPlayingPixmap)
        elif not self._sitePixmap.isNull():
            p.drawPixmap(r, self._sitePixmap)
        elif self._tab and self._tab.isPinned():
            p.drawPixmap(r, IconProvider.emptyWebIcon().pixmap(size))

        # Draw audio icon on top of site icon for pinned tabs
        if not self._animationRunning and self._audioIconDisplayed and self._tab.isPinned(
        ):
            s = size - 4
            r0 = QRect(self.width() - 4, 0, s, s)
            self._audioIconRect = r0
            c = self.palette().color(QPalette.Window)
            c.setAlpha(180)
            p.setPen(c)
            p.setBrush(c)
            p.drawEllipse(r)
            p.drawPixmap(
                r,
                self._tab.isMuted() and self.data().audioMutedPixmap
                or self.data().audioPlayingPixmap)

        # Draw background activity indicator
        if self._tab and self._tab.isPinned() and self._tab.webView(
        ).backgroundActivity():
            s = 5
            # Background
            r1 = QRect(self.width() - s - 2,
                       self.height() - s - 2, s + 2, s + 2)
            c1 = self.palette().color(QPalette.Window)
            c1.setAlpha(180)
            p.setPen(Qt.transparent)
            p.setBrush(c1)
            p.drawEllipse(r1)
            # Forground
            r2 = QRect(self.width() - s - 1, self.height() - s - 1, s, s)
            c2 = self.palette().color(QPalette.Text)
            p.setPen(Qt.transparent)
            p.setBrush(c2)
            p.drawEllipse(r2)
Ejemplo n.º 5
0
    def data(self, index, role):  # noqa C901
        '''
        @param: index QModelIndex
        @param: role int
        @return: Qvariant
        @critical: donot return '' empty string for null case, that will cause
            QTreeView row not draw, return None instead (Qt return QVariant())
        '''
        # HistoryItem
        item = self.itemFromIndex(index)

        if index.row() < 0 or not item:
            return None

        if item.isTopLevel():
            if role == self.IsTopLevelRole:
                return True
            elif role == self.TimestampStartRole:
                return item.startTimestamp()
            elif role == self.TimestampEndRole:
                return item.endTimestamp()
            elif role in (Qt.DisplayRole, Qt.EditRole):
                if index.column() == 0:
                    return item.title
                else:
                    return None
            elif role == Qt.DecorationRole:
                if index.column() == 0:
                    return QIcon.fromTheme(
                        'view-calendar',
                        QIcon(':/icons/menu/history_entry.svg'))
                else:
                    return None

            return None

        entry = item.historyEntry

        if role == self.IdRole:
            return entry.id
        elif role == self.TitleRole:
            return entry.title
        elif role == self.UrlRole:
            return entry.url
        elif role == self.UrlStringRole:
            return entry.urlString
        elif role == self.IconRole:
            return item.icon()
        elif role == self.IsTopLevelRole:
            return False
        elif role == self.TimestampStartRole:
            return -1
        elif role == self.TimestampEndRole:
            return -1
        elif role in (Qt.ToolTipRole, Qt.DisplayRole, Qt.EditRole):
            if role == Qt.ToolTipRole:
                if index.column() == 0:
                    return '%s\n%s' % (entry.title, entry.urlString)
            # fallthrough
            column = index.column()
            if column == 0:
                return entry.title
            elif column == 1:
                return entry.urlString
            elif column == 2:
                return self._s_dateTimeToString(entry.date)
            elif column == 3:
                return entry.count
        elif role == Qt.DecorationRole:
            if index.column() == 0:
                if item.icon().isNull():
                    return IconProvider.emptyWebIcon()
                else:
                    return item.icon()

        return None
Ejemplo n.º 6
0
 def icon(self, allowNull=False):
     if self.isRestored():
         return self._webView.icon(allowNull)
     if allowNull or not self._savedTab.icon.isNull():
         return self._savedTab.icon
     return IconProvider.emptyWebIcon()