<commit_before>// Copyright 2015 Endless Mobile, Inc.

const Gdk = imports.gi.Gdk;
const GObject = imports.gi.GObject;
const Gtk = imports.gi.Gtk;
const Lang = imports.lang;

const Card = imports.app.interfaces.card;
const MarginButton = imports.app.widgets.marginButton;
const Module = imports.app.interfaces.module;
const SetObjectModel = imports.search.setObjectModel;
const Utils = imports.app.utils;

/**
 * Class: PostCard
 * A postcard for the new reader app.
 */
const PostCard = new Lang.Class({
    Name: 'PostCard',
    GTypeName: 'EknPostCard',
    Extends: MarginButton.MarginButton,
    Implements: [ Module.Module, Card.Card ],

    Properties: {
        'factory': GObject.ParamSpec.override('factory', Module.Module),
        'factory-name': GObject.ParamSpec.override('factory-name', Module.Module),
        'model': GObject.ParamSpec.override('model', Card.Card),
        'title-capitalization': GObject.ParamSpec.override('title-capitalization',
            Card.Card),
        'context-capitalization': GObject.ParamSpec.override('context-capitalization',
            Card.Card),
        'highlight-string': GObject.ParamSpec.override('highlight-string', Card.Card),
        'text-halign': GObject.ParamSpec.override('text-halign', Card.Card),
        'sequence': GObject.ParamSpec.override('sequence', Card.Card),
    },

    Template: 'resource:///com/endlessm/knowledge/data/widgets/postCard.ui',
    InternalChildren: [ 'thumbnail-frame', 'title-label', 'inner-content-grid', 'shadow-frame' ],

    _init: function (props={}) {
        this.parent(props);

        this._showing_set = (this.model instanceof SetObjectModel.SetObjectModel);

        this.set_title_label_from_model(this._title_label);
        this.set_thumbnail_frame_from_model(this._thumbnail_frame);
        this.add_contextual_css_class();
        this.set_size_request(Card.MinSize.A, Card.MinSize.A);

        Utils.set_hand_cursor_on_widget(this);

        if (this._showing_set) {
            this._inner_content_grid.valign = Gtk.Align.CENTER;
            this._thumbnail_frame.margin = 13;
            this._thumbnail_frame.connect_after('draw', (widget, cr) => {
                Utils.render_border_with_arrow(this._thumbnail_frame, cr);
                cr.$dispose();  // workaround not freeing cairo context
                return Gdk.EVENT_PROPAGATE;
            });
        } else {
            this.set_context_label_from_model(this._inner_content_grid);
            this._title_label.halign = this._space_container.halign = this.text_halign;
            this._title_label.justify = Utils.alignment_to_justification(this.text_halign);
            this._title_label.xalign = Utils.alignment_to_xalign(this.text_halign);
        }
    },

    vfunc_size_allocate: function (alloc) {
        this.parent(alloc);
        let child_alloc = new Gdk.Rectangle({
            x: 0,
            width: alloc.width,
        });
        if (this._showing_set) {
            let sleeve_height = alloc.height > Card.MaxSize.B ? 120 : 80;
            child_alloc.y = (alloc.height / 2) - (sleeve_height / 2);
            child_alloc.height = sleeve_height;
        } else {
            let content_height = this._get_content_height(alloc.height);
            child_alloc.y = alloc.height - content_height;
            child_alloc.height = content_height;
        }
        this._shadow_frame.size_allocate(child_alloc);
        this.update_card_sizing_classes(alloc.height, alloc.width);
    },

    vfunc_draw: function (cr) {
        if (this._showing_set) {
            let margin = this._thumbnail_frame.margin;
            let sleeve_alloc = this._shadow_frame.get_allocation();
            let shadow_top = sleeve_alloc.y + sleeve_alloc.height;

            cr.save();
            Gdk.cairo_set_source_rgba(cr, new Gdk.RGBA({
                red: 0.6,
                green: 0.6,
                blue: 0.6,
                alpha: 1.0,
            }));<commit_msg>postCard: don't reallocate descendants after allocate<commit_after>// Copyright 2015 Endless Mobile, Inc.

const Gdk = imports.gi.Gdk;
const GObject = imports.gi.GObject;
const Gtk = imports.gi.Gtk;
const Lang = imports.lang;

const Card = imports.app.interfaces.card;
const MarginButton = imports.app.widgets.marginButton;
const Module = imports.app.interfaces.module;
const SetObjectModel = imports.search.setObjectModel;
const Utils = imports.app.utils;

/**
 * Class: PostCard
 * A postcard for the new reader app.
 */
const PostCard = new Lang.Class({
    Name: 'PostCard',
    GTypeName: 'EknPostCard',
    Extends: MarginButton.MarginButton,
    Implements: [ Module.Module, Card.Card ],

    Properties: {
        'factory': GObject.ParamSpec.override('factory', Module.Module),
        'factory-name': GObject.ParamSpec.override('factory-name', Module.Module),
        'model': GObject.ParamSpec.override('model', Card.Card),
        'title-capitalization': GObject.ParamSpec.override('title-capitalization',
            Card.Card),
        'context-capitalization': GObject.ParamSpec.override('context-capitalization',
            Card.Card),
        'highlight-string': GObject.ParamSpec.override('highlight-string', Card.Card),
        'text-halign': GObject.ParamSpec.override('text-halign', Card.Card),
        'sequence': GObject.ParamSpec.override('sequence', Card.Card),
    },

    Template: 'resource:///com/endlessm/knowledge/data/widgets/postCard.ui',
    InternalChildren: [ 'thumbnail-frame', 'title-label', 'inner-content-grid', 'shadow-frame', 'overlay' ],

    _init: function (props={}) {
        this.parent(props);

        this._showing_set = (this.model instanceof SetObjectModel.SetObjectModel);

        this.set_title_label_from_model(this._title_label);
        this.set_thumbnail_frame_from_model(this._thumbnail_frame);
        this.add_contextual_css_class();
        this.set_size_request(Card.MinSize.A, Card.MinSize.A);

        Utils.set_hand_cursor_on_widget(this);

        if (this._showing_set) {
            this._inner_content_grid.valign = Gtk.Align.CENTER;
            this._thumbnail_frame.margin = 13;
            this._thumbnail_frame.connect_after('draw', (widget, cr) => {
                Utils.render_border_with_arrow(this._thumbnail_frame, cr);
                cr.$dispose();  // workaround not freeing cairo context
                return Gdk.EVENT_PROPAGATE;
            });
        } else {
            this.set_context_label_from_model(this._inner_content_grid);
            this._title_label.halign = this._space_container.halign = this.text_halign;
            this._title_label.justify = Utils.alignment_to_justification(this.text_halign);
            this._title_label.xalign = Utils.alignment_to_xalign(this.text_halign);
        }

        this._overlay.connect('get-child-position', this._overlay_get_child_position.bind(this));
    },

    _overlay_get_child_position: function (overlay, child, allocation) {
        let width = overlay.get_allocated_width();
        let height = overlay.get_allocated_height();
        allocation.x = 0;
        allocation.width = width;
        if (this._showing_set) {
            let sleeve_height = height > Card.MaxSize.B ? 120 : 80;
            allocation.y = (height / 2) - (sleeve_height / 2);
            allocation.height = sleeve_height;
        } else {
            let content_height = this._get_content_height(height);
            allocation.y = height - content_height;
            allocation.height = content_height;
        }
        return [true, allocation];
    },

    vfunc_size_allocate: function (alloc) {
        this.parent(alloc);
        this.update_card_sizing_classes(alloc.height, alloc.width);
    },

    vfunc_draw: function (cr) {
        if (this._showing_set) {
            let margin = this._thumbnail_frame.margin;
            let sleeve_alloc = this._shadow_frame.get_allocation();
            let shadow_top = sleeve_alloc.y + sleeve_alloc.height;

            cr.save();
            Gdk.cairo_set_source_rgba(cr, new Gdk.RGBA({
                red: 0.6,
                green: 0.6,
                blue: 0.6,
                alpha: 1.0,
            }));
{'fraction_non_alphanumeric': 0.11812277907119226, 'fraction_numerical': 0.0053914961401789, 'mean_word_length': 2.6372549019607843, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3365065', 'n_tokens_mistral': 2527, 'n_tokens_neox': 2430, 'n_words': 407}