예제 #1
0
    def __init__(self, text, read_only=False, checked=False, parent=None):
        super(TodoItemEditor, self).__init__(parent=parent)
        self.setDisabled(checked)
        self.document().setDocumentMargin(common.MARGIN())
        self.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
        self.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)

        self.highlighter = Highlighter(self.document())

        self.setOpenExternalLinks(True)
        self.setOpenLinks(False)
        self.setReadOnly(False)

        if read_only:
            self.setTextInteractionFlags(QtCore.Qt.TextSelectableByMouse
                                         | QtCore.Qt.LinksAccessibleByMouse)
        else:
            self.setTextInteractionFlags(QtCore.Qt.TextEditorInteraction
                                         | QtCore.Qt.LinksAccessibleByMouse)

        self.setTabStopWidth(common.MARGIN())
        self.setUndoRedoEnabled(True)

        self.setSizePolicy(QtWidgets.QSizePolicy.Preferred,
                           QtWidgets.QSizePolicy.Fixed)
        self.setFocusPolicy(QtCore.Qt.StrongFocus)
        self.document().setUseDesignMetrics(True)
        self.document().setHtml(text)

        self.document().contentsChanged.connect(self.contentChanged)
        self.anchorClicked.connect(self.open_url)
예제 #2
0
 def pixmap(self):
     if self.state():
         return images.ImageCache.get_rsc_pixmap(u'collapse',
                                                 self._on_color,
                                                 common.MARGIN())
     return images.ImageCache.get_rsc_pixmap(u'expand', self._off_color,
                                             common.MARGIN())
예제 #3
0
    def add_location_toggles_menu(self, menu_set):
        """Adds the menu needed to change context"""
        taskfolder_pixmap = images.ImageCache.get_rsc_pixmap(
            u'folder', common.SECONDARY_TEXT, common.MARGIN())
        item_on_pixmap = images.ImageCache.get_rsc_pixmap(
            u'check', common.SECONDARY_TEXT, common.MARGIN())
        item_off_pixmap = QtGui.QPixmap()

        key = u'Change task folder'
        menu_set[key] = collections.OrderedDict()
        menu_set[u'{}:icon'.format(key)] = taskfolder_pixmap

        model = self.parent().model().sourceModel()
        parent_item = model.parent_path
        if not parent_item:
            return menu_set
        if not all(parent_item):
            return menu_set

        dir_ = QtCore.QDir(u'/'.join(parent_item))
        dir_.setFilter(QtCore.QDir.Dirs | QtCore.QDir.NoDotAndDotDot)
        for entry in sorted(dir_.entryList()):
            task_folder = model.task_folder()
            if task_folder:
                checked = task_folder.lower() == entry.lower()
            else:
                checked = False
            menu_set[key][entry] = {
                u'text': entry.title(),
                u'icon': item_on_pixmap if checked else item_off_pixmap,
                u'action': functools.partial(model.taskFolderChanged.emit, entry)
            }
        return menu_set
예제 #4
0
    def add_refresh_menu(self, menu_set):
        parent = self.parent()
        refresh_pixmap = images.ImageCache.get_rsc_pixmap(
            u'refresh', common.SECONDARY_TEXT, common.MARGIN())
        preferences_pixmap = images.ImageCache.get_rsc_pixmap(
            u'settings', common.SECONDARY_TEXT, common.MARGIN())
        quit_pixmap = images.ImageCache.get_rsc_pixmap(
            u'close', common.SEPARATOR, common.MARGIN())

        menu_set[u'Refresh'] = {
            u'action': parent.model().sourceModel().modelDataResetRequested.emit,
            u'icon': refresh_pixmap
        }

        menu_set[u'separator'] = None
        menu_set[u'Preferences...'] = {
            u'action': parent.show_preferences,
            u'icon': preferences_pixmap,
        }

        try:
            menu_set[u'separator'] = None
            menu_set[u'Quit...'] = {
                u'action': parent.parent().parent().shutdown.emit,
                u'icon': quit_pixmap,
            }
        except:
            log.error('Quit menu not added')

        return menu_set
예제 #5
0
    def add_control_favourites_menu(self, menu_set):
        """Ads the menu-items needed to add set favourite or archived status."""
        add_icon = images.ImageCache.get_rsc_pixmap(
            u'favourite', common.TEXT, common.MARGIN())
        save_icon = images.ImageCache.get_rsc_pixmap(
            u'favourite', common.ADD, common.MARGIN())
        remove_icon = images.ImageCache.get_rsc_pixmap(
            u'remove', common.REMOVE, common.MARGIN())

        menu_set[u'export_favourites'] = {
            u'text': u'Save favourites...',
            u'icon': save_icon,
            u'checkable': False,
            u'action': common.export_favourites
        }
        menu_set[u'import_favourites'] = {
            u'text': u'Import favourites...',
            u'icon': add_icon,
            u'checkable': False,
            u'action': (common.import_favourites, self.parent().favouritesChanged.emit)
        }
        menu_set['_separator_'] = {}
        menu_set[u'remove'] = {
            u'text': u'Remove all favourites',
            u'icon': remove_icon,
            u'checkable': False,
            u'action': (common.clear_favourites, self.parent().favouritesChanged.emit)
        }

        return menu_set
예제 #6
0
    def eventFilter(self, widget, event):
        """Using  the custom event filter to paint the background."""
        if event.type() == QtCore.QEvent.Paint:
            painter = QtGui.QPainter()
            painter.begin(self)
            font = common.font_db.secondary_font(
                font_size=common.MEDIUM_FONT_SIZE())[0]
            painter.setFont(font)
            painter.setRenderHints(QtGui.QPainter.Antialiasing)

            o = common.INDICATOR_WIDTH()
            rect = self.rect().marginsRemoved(QtCore.QMargins(o, o, o, o))
            painter.setBrush(QtGui.QColor(250, 250, 250, 255))
            painter.setPen(QtCore.Qt.NoPen)
            painter.drawRoundedRect(rect, o * 2, o * 2)

            center = rect.center()
            rect.setWidth(rect.width() - common.MARGIN())
            rect.setHeight(rect.height() - common.MARGIN())
            rect.moveCenter(center)

            text = u'Click the plus icon on the top to add a note'
            text = text if not len(self.todoeditors_widget.items) else u''
            common.draw_aliased_text(painter, font, rect, text,
                                     QtCore.Qt.AlignCenter,
                                     common.SECONDARY_BACKGROUND)
            painter.end()
        return False
예제 #7
0
    def paintEvent(self, event):
        """The control button's paint method - shows the the set text and
        an underline if the tab is active."""
        if not self.stacked_widget():
            return

        rect = QtCore.QRect(self.rect())

        painter = QtGui.QPainter()
        painter.begin(self)
        painter.setRenderHint(QtGui.QPainter.Antialiasing, True)

        option = QtWidgets.QStyleOptionButton()
        option.initFrom(self)
        hover = option.state & QtWidgets.QStyle.State_MouseOver
        painter.setPen(QtCore.Qt.NoPen)

        if self.current_index() == self.index:
            color = common.TEXT_SELECTED if hover else common.TEXT
            painter.setBrush(color)
        else:
            color = common.TEXT if hover else common.BACKGROUND
            painter.setBrush(color)

        font, metrics = common.font_db.primary_font(common.MEDIUM_FONT_SIZE())

        if (metrics.width(self.text()) +
            (common.MARGIN() * 0.5)) < self.rect().width():
            text = metrics.elidedText(self.text(), QtCore.Qt.ElideRight,
                                      self.rect().width())
            width = metrics.width(text)

            x = (self.width() / 2.0) - (width / 2.0)
            y = self.rect().center().y() + (metrics.ascent() * 0.5)
            path = delegate.get_painter_path(x, y, font, text)
            painter.drawPath(path)
        else:
            pixmap = images.ImageCache.get_rsc_pixmap(self.icon, color,
                                                      common.MARGIN())
            # _rect = QtCore.QRect(self.rect())
            _rect = pixmap.rect()
            _rect.moveCenter(self.rect().center())
            painter.drawPixmap(_rect, pixmap, pixmap.rect())

        rect.setHeight(common.ROW_SEPARATOR() * 2.0)
        painter.setPen(QtCore.Qt.NoPen)
        rect.setWidth(self.rect().width())

        if self.current_index() == self.index:
            painter.setOpacity(0.9)
            color = common.TEXT if hover else common.REMOVE
        else:
            painter.setOpacity(0.3)
            color = common.TEXT if hover else common.FAVOURITE

        painter.setBrush(color)
        painter.drawRect(rect)
        painter.end()
예제 #8
0
 def set_pixmap(self, checked):
     if checked:
         pixmap = images.ImageCache.get_rsc_pixmap(u'check',
                                                   common.BACKGROUND,
                                                   common.MARGIN())
         self.setPixmap(pixmap)
     else:
         pixmap = images.ImageCache.get_rsc_pixmap(u'check', common.ADD,
                                                   common.MARGIN())
         self.setPixmap(pixmap)
예제 #9
0
    def setDisabled(self, b):
        """Custom disabled function."""
        if b:
            pixmap = images.ImageCache.get_rsc_pixmap(u'drag_indicator',
                                                      common.TEXT_SELECTED,
                                                      common.MARGIN() * 0.66)
        else:
            pixmap = images.ImageCache.get_rsc_pixmap(u'drag_indicator',
                                                      common.TEXT,
                                                      common.MARGIN() * 0.66)

        self.setPixmap(pixmap)
예제 #10
0
    def add_sort_menu(self, menu_set):
        """Creates the menu needed to set the sort-order of the list."""
        sort_menu_icon = images.ImageCache.get_rsc_pixmap(
            u'sort', common.SECONDARY_TEXT, common.MARGIN())
        arrow_up_icon = images.ImageCache.get_rsc_pixmap(
            u'arrow_up', common.SECONDARY_TEXT, common.MARGIN())
        arrow_down_icon = images.ImageCache.get_rsc_pixmap(
            u'arrow_down', common.SECONDARY_TEXT, common.MARGIN())

        item_on_icon = images.ImageCache.get_rsc_pixmap(
            u'check', common.ADD, common.MARGIN())

        m = self.parent().model().sourceModel()
        sortorder = m.sort_order()
        sortrole = m.sort_role()

        sort_by_name = sortrole == common.SortByNameRole
        sort_modified = sortrole == common.SortByLastModifiedRole
        sort_size = sortrole == common.SortBySizeRole

        menu_set[u'Sort'] = collections.OrderedDict()

        menu_set[u'Sort:icon'] = sort_menu_icon
        menu_set[u'Sort'][u'Order'] = {
            u'text': u'Ascending' if not sortorder else u'Descending',
            u'checkable': False,
            # u'checked': not sortorder,
            u'icon': arrow_down_icon if not sortorder else arrow_up_icon,
            u'action': lambda: m.sortingChanged.emit(sortrole, not sortorder)
        }

        menu_set[u'Sort'][u'separator'] = {}

        menu_set[u'Sort'][u'Name'] = {
            u'icon': item_on_icon if sort_by_name else QtGui.QPixmap(),
            # u'ckeckable': True,
            # u'checked': True if sort_by_name else False,
            u'action': lambda: m.sortingChanged.emit(common.SortByNameRole, sortorder)
        }
        menu_set[u'Sort'][u'Date modified'] = {
            u'icon': item_on_icon if sort_modified else QtGui.QPixmap(),
            # u'ckeckable': True,
            # u'checked': True if sort_modified else False,
            u'action': lambda: m.sortingChanged.emit(common.SortByLastModifiedRole, sortorder)
        }
        menu_set[u'Sort'][u'Size'] = {
            u'icon': item_on_icon if sort_size else QtGui.QPixmap(),
            # u'ckeckable': True,
            # u'checked': True if sort_size else False,
            u'action': lambda: m.sortingChanged.emit(common.SortBySizeRole, sortorder)
        }
        return menu_set
예제 #11
0
    def _create_UI(self):
        QtWidgets.QVBoxLayout(self)
        o = common.MARGIN()
        self.layout().setContentsMargins(o, o, o, o)
        self.layout().setSpacing(o)

        row = common_ui.add_row(u'', parent=self)
        self.hide_button = common_ui.ClickableIconButton(
            u'close', (common.REMOVE, common.REMOVE),
            common.MARGIN(),
            description=u'Hide',
            parent=row)

        bookmark = u'{}/{}/{}'.format(self.server, self.job, self.root)
        source = images.get_thumbnail_path(self.server, self.job, self.root,
                                           bookmark)

        pixmap = images.ImageCache.get_pixmap(source, row.height())
        if not pixmap:
            source = images.get_placeholder_path(
                bookmark, fallback=u'thumb_bookmark_gray')
            pixmap = images.ImageCache.get_pixmap(source, row.height())

        if pixmap:
            thumbnail = QtWidgets.QLabel(parent=self)
            thumbnail.setPixmap(pixmap)
            row.layout().addWidget(thumbnail, 0)
            row.layout().addSpacing(o * 0.5)

        text = u'{}  |  {}'.format(self.job.upper(), self.root.upper())
        label = common_ui.PaintedLabel(text, size=common.LARGE_FONT_SIZE())

        row.layout().addWidget(label)
        row.layout().addStretch(1)
        row.layout().addWidget(self.hide_button, 0)

        # *****************************************

        self.templates_widget = managebookmarks.TemplatesWidget(u'asset',
                                                                parent=self)
        self.layout().addWidget(self.templates_widget, 1)

        s = u'Independent of the template, basic <span style="color:rgba({ADD});">mode</span> and \
<span style="color:rgba({ADD});">task</span> are defined in \
<span style="color:rgba({H});">Preferences -> Default Paths</span>. \
Ideally, both the template and the preferences should define the same folders.'.format(
            ADD=common.rgb(common.ADD),
            H=common.rgb(common.TEXT_SELECTED),
        )
        common_ui.add_description(s, label='hint', parent=self)
        self.layout().addStretch(1)
예제 #12
0
    def add_set_generate_thumbnails_menu(self, menu_set):
        item_on_icon = images.ImageCache.get_rsc_pixmap(
            u'check', common.ADD, common.MARGIN())
        item_off_icon = images.ImageCache.get_rsc_pixmap(
            u'spinner_btn', common.SECONDARY_TEXT, common.MARGIN())

        model = self.parent().model().sourceModel()

        enabled = model.generate_thumbnails_enabled()
        menu_set['generate'] = {
            'text': 'Generate thumbnails',
            'icon': item_on_icon if enabled else item_off_icon,
            'action': lambda: model.set_generate_thumbnails_enabled(not enabled)
        }
        return menu_set
예제 #13
0
    def _create_UI(self):
        QtWidgets.QVBoxLayout(self)
        o = common.MARGIN()
        self.layout().setContentsMargins(o, o, o, o)
        self.layout().setSpacing(common.INDICATOR_WIDTH())

        height = common.ROW_HEIGHT() * 0.7
        row = common_ui.add_row(None, height=height, padding=None, parent=self)

        self.channel_button = common_ui.ClickableIconButton(
            u'slack',
            (common.TEXT, common.TEXT),
            height,
        )
        label = common_ui.PaintedLabel(u'Send Message',
                                       size=common.LARGE_FONT_SIZE(),
                                       parent=row)
        label.setFixedHeight(height)
        self.hide_button = common_ui.ClickableIconButton(
            u'close', (common.REMOVE, common.REMOVE), height, parent=row)

        row.layout().addWidget(label, 0)
        row.layout().addStretch(1)
        row.layout().addWidget(self.channel_button, 0)
        row.layout().addWidget(self.hide_button, 0)

        self.message_widget = MessageWidget(self.token, parent=self)
        self.layout().addSpacing(o * 0.5)
        self.layout().addWidget(self.message_widget)

        self.send_button = common_ui.PaintedButton(u'Send', parent=self)
        self.layout().addSpacing(o)
        self.layout().addWidget(self.send_button)
        self.layout().addSpacing(o * 0.5)
예제 #14
0
    def _create_UI(self):
        QtWidgets.QVBoxLayout(self)
        o = common.MARGIN()
        self.layout().setContentsMargins(o, o * 0.5, o, o)
        self.layout().setSpacing(0)

        row = common_ui.add_row(None, padding=None, parent=self)
        self.hide_button = common_ui.ClickableIconButton(
            u'close', (common.REMOVE, common.REMOVE),
            common.ROW_HEIGHT() * 0.6)
        label = common_ui.PaintedLabel(u'Preferences',
                                       size=common.LARGE_FONT_SIZE())
        row.layout().addWidget(label, 0)
        row.layout().addStretch(1)
        row.layout().addWidget(self.hide_button, 0)
        self.hide_button.clicked.connect(
            lambda: self.done(QtWidgets.QDialog.Rejected))

        splitter = QtWidgets.QSplitter(parent=self)
        self.layout().addWidget(splitter)

        self.sections_list_widget = SectionSwitcherWidget(parent=self)
        splitter.addWidget(self.sections_list_widget)

        scroll_area = QtWidgets.QScrollArea(parent=self)
        scroll_area.setWidgetResizable(True)
        splitter.addWidget(scroll_area)

        self.sections_stack_widget = SectionsStackWidget(parent=self)
        scroll_area.setWidget(self.sections_stack_widget)
예제 #15
0
 def __init__(self, parent=None):
     super(MinimizeButton,
           self).__init__(u'minimize',
                          (common.REMOVE, common.SECONDARY_TEXT),
                          common.MARGIN() - common.INDICATOR_WIDTH(),
                          description=u'Click to minimize the window...',
                          parent=parent)
예제 #16
0
    def paintEvent(self, event):
        """Custom paint event"""
        painter = QtGui.QPainter()
        painter.begin(self)
        painter.setRenderHint(QtGui.QPainter.Antialiasing)

        w = self._width + 0.01
        h = self._height + 0.01

        factor = float(min((self.width(), self.height())) -
                       common.MARGIN()) / max(float(w), float(h))
        w *= factor
        h *= factor

        painter.setBrush(common.SEPARATOR)
        painter.setPen(QtCore.Qt.NoPen)
        painter.setOpacity(0.3)
        painter.drawRect(self.rect())
        painter.setOpacity(1.0)

        rect = QtCore.QRect(0, 0, w, h)
        rect.moveCenter(self.rect().center())

        # Outline
        painter.setOpacity(0.2)
        pen = QtGui.QPen(common.ADD)
        pen.setWidthF(common.ROW_SEPARATOR() * 2.0)
        pen.setStyle(QtCore.Qt.SolidLine)
        pen.setJoinStyle(QtCore.Qt.RoundJoin)
        painter.setPen(pen)
        painter.setBrush(QtCore.Qt.NoBrush)
        painter.drawRect(rect)

        painter.setPen(QtCore.Qt.NoPen)
        painter.setBrush(common.ADD)
        painter.drawRect(rect)
        painter.setOpacity(1.0)

        painter.setPen(common.TEXT)
        font, metrics = common.font_db.primary_font(
            font_size=common.SMALL_FONT_SIZE())
        painter.setFont(font)
        _rect = self.rect()
        _rect.setLeft(rect.left() + common.SMALL_FONT_SIZE())

        text = u'{w}{h}{fps}{pre}{start}{duration}'.format(
            w=u'{}px'.format(int(self._width)) if self._width else u'',
            h=u' * {}px'.format(int(self._height)) if self._height else u'',
            fps=u'  |  {}fps'.format(self._fps) if self._fps else u'',
            pre=u'\n{}'.format(self._prefix) if self._prefix else u'',
            start=u'\nIn: {}'.format(int(self._start)) if self._start else u'',
            duration=u'\nOut: {}\nDuration: {}'.format(
                int(self._start) + int(self._duration),
                int(self._duration) if self._duration else u'')
            if self._duration else u'')
        painter.drawText(
            _rect, QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter
            | QtCore.Qt.TextWordWrap,
            text if text else u'Bookmark not yet configured')
        painter.end()
예제 #17
0
    def add_visibility_menu(self, menu_set):
        """Actions associated with the visibility of the widget."""
        def toggle_window_flag():
            """Sets the WindowStaysOnTopHint for the window."""
            flags = self.parent().windowFlags()
            self.hide()
            if flags & QtCore.Qt.WindowStaysOnTopHint:
                flags = flags & ~QtCore.Qt.WindowStaysOnTopHint
            else:
                flags = flags | QtCore.Qt.WindowStaysOnTopHint
            self.parent().setWindowFlags(flags)
            self.parent().showNormal()
            self.parent().activateWindow()

        active = self.parent().windowFlags() & QtCore.Qt.WindowStaysOnTopHint
        on_pixmap = images.ImageCache.get_rsc_pixmap(u'check', common.ADD,
                                                     common.MARGIN())

        menu_set[u'Keep on top of other windows'] = {
            u'pixmap': on_pixmap if active else None,
            u'action': toggle_window_flag
        }
        menu_set[u'Restore window...'] = {u'action': show_window}
        menu_set[u'separator1'] = {}
        menu_set[u'Quit'] = {u'action': self.parent().shutdown.emit}
        return menu_set
예제 #18
0
 def __init__(self, parent=None):
     super(RemoveNoteButton,
           self).__init__(u'remove', (common.REMOVE, common.REMOVE),
                          common.MARGIN() * 0.66,
                          description=u'Click to remove this note',
                          parent=parent)
     self.clicked.connect(self.remove_note)
예제 #19
0
    def _create_UI(self):
        o = 0
        top_widget = QtWidgets.QWidget(parent=self)
        QtWidgets.QVBoxLayout(top_widget)
        top_widget.layout().setContentsMargins(o, o, o, o)
        top_widget.layout().setSpacing(0)
        self.addWidget(top_widget)

        self.message_widget = QtWidgets.QTextEdit(parent=self)
        _o = common.MARGIN()
        self.message_widget.document().setDocumentMargin(_o)
        self.message_widget.setPlaceholderText(u'Enter a message to send...')
        self.message_widget.setAcceptRichText(False)
        self.message_widget.moveCursor(QtGui.QTextCursor.End)

        top_widget.layout().addWidget(self.message_widget, 0)

        bottom_widget = QtWidgets.QWidget(parent=self)
        o = common.MARGIN() * 0.5
        height = common.ROW_HEIGHT()
        QtWidgets.QVBoxLayout(bottom_widget)
        bottom_widget.layout().setContentsMargins(o, 0, o, 0)
        bottom_widget.layout().setSpacing(0)

        row = common_ui.add_row(u'', height=height, parent=bottom_widget)
        row.layout().setAlignment(QtCore.Qt.AlignBottom)
        label = common_ui.PaintedLabel(u'Channels & Direct Messages',
                                       parent=self)
        row.layout().addWidget(label, 0)

        row = common_ui.add_row(u'', height=height, parent=bottom_widget)
        row.layout().setAlignment(QtCore.Qt.AlignBottom)

        self.user_filter = common_ui.LineEdit(parent=self)
        self.user_filter.setAlignment(QtCore.Qt.AlignVCenter
                                      | QtCore.Qt.AlignRight)
        self.user_filter.setPlaceholderText(u'Search...')
        row.layout().addWidget(self.user_filter, 1)

        self.users_widget = UsersWidget(self.token, parent=self)

        bottom_widget.layout().addWidget(self.users_widget)

        self.addWidget(bottom_widget)
        self.addWidget(top_widget)

        self.setSizes([common.WIDTH() * 0.08, common.WIDTH() * 0.2])
예제 #20
0
    def add_switch_menu(self, menu_set, widget, label):
        if hasattr(widget.model(), 'sourceModel'):
            model = widget.model().sourceModel()
        else:
            model = widget.model()
        active_index = model.active_index()
        items = model.model_data().items()
        items = sorted(items,
                       key=lambda x: x[1][QtCore.Qt.DisplayRole].lower())

        off_pixmap = images.ImageCache.get_rsc_pixmap(u'folder',
                                                      common.SECONDARY_TEXT,
                                                      common.MARGIN())
        on_pixmap = images.ImageCache.get_rsc_pixmap(u'check', common.ADD,
                                                     common.MARGIN())

        menu_set[label] = {u'disabled': True}
        for idx, item in items:
            if item[common.FlagsRole] & common.MarkedAsArchived:
                continue
            name = item[QtCore.Qt.DisplayRole]
            active = False
            if active_index.isValid():
                n = active_index.data(QtCore.Qt.DisplayRole)
                active = n.lower() == name.lower()

            index = model.index(idx, 0)
            if hasattr(model, 'mapFromSource'):
                index = widget.model().mapFromSource(index)

            thumbnail_path = images.get_thumbnail_path(
                item[common.ParentPathRole][0],
                item[common.ParentPathRole][1],
                item[common.ParentPathRole][2],
                item[QtCore.Qt.StatusTipRole],
            )
            pixmap = images.ImageCache.get_pixmap(thumbnail_path,
                                                  common.MARGIN() * 2)
            pixmap = pixmap if pixmap else off_pixmap
            pixmap = on_pixmap if active else pixmap
            icon = QtGui.QIcon(pixmap)
            menu_set[name.upper()] = {
                u'icon': icon,
                u'action': functools.partial(widget.activate, index)
            }
        return menu_set
예제 #21
0
 def add_manage_bookmarks_menu(self, menu_set):
     pixmap = images.ImageCache.get_rsc_pixmap(
         u'bookmark2', common.ADD, common.MARGIN())
     menu_set[u'Manage bookmarks'] = {
         u'text': u'Manage bookmarks',
         u'icon': pixmap,
         u'action': self.parent().manage_bookmarks.open
     }
     return menu_set
예제 #22
0
    def paintEvent(self, event):
        painter = QtGui.QPainter()
        painter.begin(self)

        painter.setRenderHint(QtGui.QPainter.Antialiasing)

        pen = QtGui.QPen(common.SEPARATOR)
        pen.setWidthF(common.ROW_SEPARATOR())
        painter.setPen(pen)

        o = common.MARGIN()
        rect = self.rect().marginsRemoved(QtCore.QMargins(o, o, o, o))
        rect.setHeight(common.ROW_HEIGHT() + (common.MARGIN() * 2))
        painter.setBrush(common.SECONDARY_BACKGROUND)
        painter.setOpacity(0.9)
        painter.drawRoundedRect(
            rect, common.INDICATOR_WIDTH(), common.INDICATOR_WIDTH())
        painter.end()
예제 #23
0
    def add_mode_toggles_menu(self, menu_set):
        """Ads the menu-items needed to add set favourite or archived status."""
        favourite_on_icon = images.ImageCache.get_rsc_pixmap(
            u'favourite', common.SECONDARY_TEXT, common.MARGIN())
        favourite_off_icon = images.ImageCache.get_rsc_pixmap(
            u'favourite', common.SECONDARY_TEXT, common.MARGIN())
        archived_on_icon = images.ImageCache.get_rsc_pixmap(
            u'archived', common.SECONDARY_TEXT, common.MARGIN())
        archived_off_icon = images.ImageCache.get_rsc_pixmap(
            u'archived', common.SECONDARY_TEXT, common.MARGIN())

        favourite = self.index.flags() & common.MarkedAsFavourite
        archived = self.index.flags() & common.MarkedAsArchived

        pixmap = archived_off_icon if archived else archived_on_icon
        if self.__class__.__name__ == u'BookmarksWidgetContextMenu':
            pixmap = images.ImageCache.get_rsc_pixmap(
                u'remove', common.REMOVE, common.MARGIN())
            text = u'Remove'
        else:
            text = u'Restore' if archived else u'Archive'
        menu_set[u'archived'] = {
            u'text': text,
            u'icon': pixmap,
            u'checkable': False,
            u'action': functools.partial(
                self.parent().toggle_item_flag,
                self.index,
                common.MarkedAsArchived,
                state=not archived
            )
        }
        menu_set[u'favourite'] = {
            u'text': u'Remove favourite' if favourite else u'Favourite',
            u'icon': favourite_off_icon if favourite else favourite_on_icon,
            u'checkable': False,
            u'action': functools.partial(
                self.parent().toggle_item_flag,
                self.index,
                common.MarkedAsFavourite,
                state=not favourite
            )
        }
        return menu_set
예제 #24
0
def add_row(label, parent=None, padding=common.MARGIN(), height=common.ROW_HEIGHT(), cls=None, vertical=False):
    """Utility method for creating a row widget.

    Returns:
        QWidget: row widget.

    """
    if cls:
        w = cls(parent=parent)
    else:
        w = QtWidgets.QWidget(parent=parent)

    if vertical:
        QtWidgets.QVBoxLayout(w)
    else:
        QtWidgets.QHBoxLayout(w)

    w.layout().setContentsMargins(0, 0, 0, 0)
    w.layout().setSpacing(common.INDICATOR_WIDTH())
    w.layout().setAlignment(QtCore.Qt.AlignCenter)

    w.setSizePolicy(
        QtWidgets.QSizePolicy.Expanding,
        QtWidgets.QSizePolicy.Expanding,
    )
    if height:
        w.setFixedHeight(height)

    w.setAttribute(QtCore.Qt.WA_NoBackground)
    w.setAttribute(QtCore.Qt.WA_TranslucentBackground)

    if label:
        l = PaintedLabel(label, size=common.SMALL_FONT_SIZE(),
                         color=common.SECONDARY_TEXT, parent=parent)
        l.setFixedWidth(common.MARGIN() * 6.6667)
        l.setDisabled(True)
        if padding:
            w.layout().addSpacing(padding)
        w.layout().addWidget(l, 0)

    if parent:
        parent.layout().addWidget(w, 1)

    return w
예제 #25
0
    def paintEvent(self, event):
        """Drawing a rounded background help to identify that the widget
        is in standalone mode."""
        painter = QtGui.QPainter()
        painter.begin(self)
        painter.setRenderHint(QtGui.QPainter.Antialiasing)
        painter.setRenderHint(QtGui.QPainter.SmoothPixmapTransform)

        rect = QtCore.QRect(self.rect())
        pen = QtGui.QPen(QtGui.QColor(35, 35, 35, 255))
        pen.setWidth(1.0)
        painter.setPen(pen)
        painter.setBrush(common.SEPARATOR.darker(110))

        if self._frameless is True:
            o = common.INDICATOR_WIDTH()
            rect = rect.marginsRemoved(QtCore.QMargins(o, o, o, o))
            painter.drawRoundedRect(rect, o * 3, o * 3)
        else:
            painter.drawRect(rect)

        if not self._initialized:
            font, metrics = common.font_db.primary_font(
                common.MEDIUM_FONT_SIZE())
            rect = QtCore.QRect(self.rect())
            align = QtCore.Qt.AlignCenter
            color = QtGui.QColor(255, 255, 255, 80)

            pixmaprect = QtCore.QRect(rect)
            center = pixmaprect.center()
            s = common.ASSET_ROW_HEIGHT() * 1.5
            o = common.MARGIN()

            pixmaprect.setWidth(s)
            pixmaprect.setHeight(s)
            pixmaprect.moveCenter(center)

            painter.setBrush(QtGui.QColor(0, 0, 0, 20))
            pen = QtGui.QPen(QtGui.QColor(0, 0, 0, 20))
            painter.setPen(pen)

            painter.drawRoundedRect(
                pixmaprect.marginsAdded(
                    QtCore.QMargins(o * 3, o * 3, o * 3, o * 3)), o, o)

            pixmap = images.ImageCache.get_rsc_pixmap(u'icon_bw', None, s)
            painter.setOpacity(0.5)
            painter.drawPixmap(pixmaprect, pixmap, pixmap.rect())
            painter.setOpacity(1.0)

            rect.setTop(pixmaprect.bottom() + (o * 0.5))
            rect.setHeight(metrics.height())
            common.draw_aliased_text(painter, font, rect, self.init_progress,
                                     align, color)

        painter.end()
예제 #26
0
    def _create_UI(self):
        if self._frameless is True:
            o = common.INDICATOR_WIDTH()  # offset around the widget
        else:
            o = 0

        QtWidgets.QVBoxLayout(self)
        self.layout().setContentsMargins(o, o, o, o)
        self.layout().setSpacing(0)
        self.setContextMenuPolicy(QtCore.Qt.NoContextMenu)

        self.setSizePolicy(QtWidgets.QSizePolicy.Minimum,
                           QtWidgets.QSizePolicy.Minimum)

        self.headerwidget = HeaderWidget(parent=self)
        self.stackedwidget = StackedWidget(parent=self)
        self.bookmarkswidget = BookmarksWidget(parent=self)
        self.assetswidget = AssetsWidget(parent=self)
        self.fileswidget = FilesWidget(parent=self)
        self.favouriteswidget = FavouritesWidget(parent=self)

        self.stackedwidget.addWidget(self.bookmarkswidget)
        self.stackedwidget.addWidget(self.assetswidget)
        self.stackedwidget.addWidget(self.fileswidget)
        self.stackedwidget.addWidget(self.favouriteswidget)

        # Setting the tab now before we do any more initialisation
        idx = settings.local_settings.value(u'widget/mode')
        idx = 0 if idx is None or False else idx
        idx = 0 if idx < 0 else idx
        idx = 3 if idx > 3 else idx
        self.stackedwidget._setCurrentIndex(idx)

        self.listcontrolwidget = ListControlWidget(parent=self)

        if self._frameless:
            self.layout().addWidget(self.headerwidget)
        self.layout().addWidget(self.listcontrolwidget)
        self.layout().addWidget(self.stackedwidget)

        height = common.MARGIN() + (common.INDICATOR_WIDTH() * 2)
        row = common_ui.add_row(None, padding=0, height=height, parent=self)
        row.layout().setSpacing(0)
        row.layout().setContentsMargins(0, 0, 0, 0)

        self.statusbar = StatusBar(height, parent=self)
        self.solo_button = ToggleModeButton(height, parent=self)
        self.solo_button.message.connect(
            lambda s: self.statusbar.showMessage(s, 4000))

        self.thread_monitor = threads.ThreadMonitor(parent=self)

        row.layout().addWidget(self.thread_monitor, 0)
        row.layout().addWidget(self.statusbar, 1)
        row.layout().addWidget(self.solo_button, 0)
예제 #27
0
        def add_section(label, description, data):
            """Utility method for creating the layout needed to edit default paths."""
            height = common.ROW_HEIGHT() * 0.8
            o = common.MARGIN()

            grp = common_ui.get_group(parent=self)
            grp.layout().setContentsMargins(o, o, o, o)
            grp.layout().setSpacing(0)

            label = common_ui.PaintedLabel(label,
                                           size=common.LARGE_FONT_SIZE(),
                                           parent=self)
            grp.layout().addWidget(label)
            grp.layout().addSpacing(o)

            if description:
                common_ui.add_description(description, label=None, parent=grp)
                grp.layout().addSpacing(o)

            scroll_area = QtWidgets.QScrollArea(parent=self)
            scroll_area.setWidgetResizable(True)
            scroll_area.setMaximumHeight(common.HEIGHT() * 0.66)
            scroll_area.setAttribute(QtCore.Qt.WA_NoBackground)
            scroll_area.setAttribute(QtCore.Qt.WA_TranslucentBackground)
            grp.layout().addWidget(scroll_area)

            _row = common_ui.add_row(None,
                                     vertical=True,
                                     padding=None,
                                     height=None,
                                     parent=grp)
            _row.layout().setContentsMargins(0, 0, 0, 0)
            _row.layout().setSpacing(0)
            scroll_area.setWidget(_row)

            for k, v in sorted(data.items()):
                label = u'<span style="color:rgba({ADD});">{k}</span> - {v}:'.format(
                    ADD=common.rgb(common.ADD),
                    k=k.upper(),
                    v=v[u'description'])
                row = common_ui.add_row(None,
                                        padding=None,
                                        height=height,
                                        parent=_row)
                common_ui.add_description(label, label=u'', parent=row)
                row = common_ui.add_row(None,
                                        padding=None,
                                        height=height,
                                        parent=_row)
                line_edit = common_ui.add_line_edit(v[u'default'], parent=row)
                line_edit.setAlignment(QtCore.Qt.AlignLeft)
                line_edit.setText(v[u'value'])
                line_edit.textChanged.connect(
                    functools.partial(text_changed, data, k))
예제 #28
0
    def add_collapse_sequence_menu(self, menu_set):
        """Adds the menu needed to change context"""
        expand_pixmap = images.ImageCache.get_rsc_pixmap(
            u'expand', common.SECONDARY_TEXT, common.MARGIN())
        collapse_pixmap = images.ImageCache.get_rsc_pixmap(
            u'collapse', common.ADD, common.MARGIN())

        currenttype = self.parent().model().sourceModel().data_type()
        newtype = common.SequenceItem if currenttype == common.FileItem else common.FileItem
        groupped = currenttype == common.SequenceItem

        menu_set[u'collapse'] = {
            u'text': u'Expand sequences' if groupped else u'Group sequences',
            u'icon': expand_pixmap if groupped else collapse_pixmap,
            u'checkable': False,
            # u'checked': groupped,
            u'action': functools.partial(
                self.parent().model().sourceModel().dataTypeChanged.emit, newtype)
        }
        return menu_set
예제 #29
0
    def mouseMoveEvent(self, event):
        """The drag operation is initiated here."""
        if not isinstance(event, QtGui.QMouseEvent):
            return
        app = QtWidgets.QApplication.instance()
        left_button = event.buttons() & QtCore.Qt.LeftButton
        if not left_button:
            return

        parent_widget = self.parent()
        editor = parent_widget.findChild(TodoItemEditor)
        drag = QtGui.QDrag(parent_widget)

        # Setting Mime Data
        mime_data = QtCore.QMimeData()
        mime_data.setData(u'bookmarks/todo-drag', QtCore.QByteArray(''))
        drag.setMimeData(mime_data)

        # Drag pixmap
        # Transparent image
        pixmap = QtGui.QPixmap(parent_widget.size())
        parent_widget.render(pixmap)

        drag.setPixmap(pixmap)
        drag.setHotSpot(
            QtCore.QPoint(pixmap.width() - ((common.MARGIN() * 0.66) * 2),
                          pixmap.height() / 2.0))

        # Drag origin indicator
        pixmap = QtGui.QPixmap(parent_widget.size())

        painter = QtGui.QPainter()
        painter.begin(pixmap)
        painter.setPen(QtGui.QPen(QtCore.Qt.NoPen))
        painter.setBrush(QtGui.QBrush(QtGui.QColor(200, 200, 200, 255)))
        painter.drawRect(pixmap.rect())
        painter.end()

        overlay_widget = QtWidgets.QLabel(parent=parent_widget)
        overlay_widget.setFixedSize(parent_widget.size())
        overlay_widget.setPixmap(pixmap)

        # Preparing the drag...
        parent_widget.parent().separator.setHidden(False)
        overlay_widget.show()

        # Starting the drag...
        drag.exec_(QtCore.Qt.CopyAction)

        # Cleanup after drag has finished...
        overlay_widget.close()
        overlay_widget.deleteLater()
        parent_widget.parent().separator.setHidden(True)
예제 #30
0
    def __init__(self, pixmap, text, parent=None):
        super(DragPixmap, self).__init__(parent=parent)
        self._pixmap = pixmap
        self._text = text

        font, metrics = common.font_db.primary_font(common.MEDIUM_FONT_SIZE())
        self._text_width = metrics.width(text)

        width = self._text_width + common.MARGIN()
        width = common.WIDTH() + common.MARGIN() if width > common.WIDTH(
        ) else width

        self.setFixedHeight(pixmap.height())
        self.setFixedWidth(pixmap.width() + common.INDICATOR_WIDTH() + width +
                           common.INDICATOR_WIDTH())

        self.setAttribute(QtCore.Qt.WA_NoSystemBackground)
        self.setAttribute(QtCore.Qt.WA_TranslucentBackground)
        self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
        self.setWindowFlags(QtCore.Qt.FramelessWindowHint | QtCore.Qt.Window)
        self.setAttribute(QtCore.Qt.WA_TransparentForMouseEvents)
        self.adjustSize()